c语言之变参函数、calloc和布尔类型bool
来源:互联网 发布:苍南县网络问政平台 编辑:程序博客网 时间:2024/06/04 19:10
#include <stdio.h>#include <stdarg.h>#include <stdlib.h>#include <assert.h>#include <stddef.h>#include <stdbool.h>#include <stdint.h>//c语言之变参函数、calloc和布尔类型boolvoid simple_printf(const char* fmt, ...){ va_list args; va_start(args, fmt); while (*fmt != '\0') { if (*fmt == 'd') { int i = va_arg(args, int); printf("%d\n", i); } else if (*fmt == 'c') { // note automatic conversion to integral type int c = va_arg(args, int); printf("%c\n", c); } else if (*fmt == 'f') { double d = va_arg(args, double); printf("%f\n", d); } else if (*fmt == 'l') { double d = va_arg(args, double); printf("%lf\n", d); } ++fmt; } va_end(args);}//http://zh.cppreference.com/w/c/programvoid test_exit(){ int a; scanf("%d",&a); if(a==1) { abort(); }else if(a==2) { exit(EXIT_SUCCESS); }else if(a==3) { //quick_exit();//c99标准 }else if(a==4) { // _Exit(EXIT_FAILURE);//c99标准 }else if(a==5) { assert(a==6); }}void test_calloc(){ int *p1 = calloc(4, sizeof(int)); // 分配并清零4个int的数组 int *p2 = calloc(1, sizeof(int[4])); // 等价,直接命名数组类型 int *p3 = calloc(4, sizeof *p3); // 等价,免去重复类型名 if(p2) { for(int n=0; n<4; ++n) // 打印数组 printf("p2[%d] == %d\n", n, p2[n]); } free(p1); free(p2); free(p3); char* line=calloc(100,sizeof(char));//分配并清零内存 strcpy(line,"yunshouhu\n"); printf(line); free(line);}int test_bool(){ bool a=true, b=false; printf("%d\n", a&&b); printf("%d\n", a||b); printf("%d\n", !b);}int main(void){ simple_printf("dcffl", 3, 'a', 1.999, 42.5,1024.0); test_calloc(); test_bool(); test_exit();}
0 0
- c语言之变参函数、calloc和布尔类型bool
- C语言中的布尔(bool)类型
- C语言的布尔类型(_Bool, bool)
- C语言中的布尔(bool)类型
- C语言的布尔类型bool
- 浅谈C语言中的布尔(bool)类型
- 浅谈C语言中的布尔(bool)类型
- 关于C和C++的布尔类型,_Bool和bool
- C语言之calloc函数
- C语言之calloc函数
- c++之超越c的语法01-bool 布尔类型
- 【iOS开发之Objective-C】布尔(Boolean)类型--BOOL
- C++对C的扩展之bool(布尔类型)
- C语言bool类型
- C 语言bool类型
- C语言 bool类型
- C语言函数calloc
- C语言函数calloc
- mp4文件结构
- beego获取用户请求参数的方法
- 使用C#邮件发送需要邮箱开通smtp功能
- Hibernate报错问题解决
- QT--base_20161202控件
- c语言之变参函数、calloc和布尔类型bool
- Spring学习笔记(四)
- 10.5 处理2D信息
- 计算机科学(Computer Science)到底学什么?
- FJNU第二十届低年级程序设计竞赛(正式赛)-Problem C-汪老司机(简单DP)
- 10.6 使用颜色
- Borda count
- 延时执行的方法
- SoapUi负载测试