1、未初始化的枚举变量

 /* uninitialized-enum.c */
#include <stdio.h> enum color{white = , black, blue}; int main(void)
{
enum color bird; printf("bird = %d\n", bird); return ;
}

输出结果:

$ ./uninitialized-enum
bird = 2130567168
$

2、十六进制数与switch语句测试

 /* test.cpp */
#include <iostream> using namespace std; enum color{green, yellow, red, blue, black}; int main(void)
{
int i = 0x3e - ; cout << "i = " << i << endl; color bird = blue;
switch(bird){
case green:
break;
case yellow:
break;
cout << "Hello, world!" << endl;
case red:
break;
cout << "Hello, world!" << endl;
case blue:
cout << "Yes, the color of this bird is blue!" << endl;
break;
default:
cout << "No, byebye!" << endl;
break;
} return ;
}

输出结果:

$ ./test
i = 61
Yes, the color of this bird is blue!
$

3、sizeof关键字和处理器的字节序

 #include <stdio.h>

 int main(void)
{
char str[] = { 0x01, 0x00, 0x00, 0x00, 0x04, 0x01, 0x06, 0x00, 0x01, 0x02, 0x03, 0x04, 0x10, 0x10 };
unsigned ret, lid; ret = sizeof str;
printf("ret = %d\n", ret);
lid = *(unsigned *)(str+);
printf("lid = %d\n", lid); return ;
}

备注:Intel Core处理器的字节序是小端序。

输出结果:

$ ./test
ret = 14
lid = 393476 (0x00, 0x06, 0x01, 0x04)
$

4、C语言中的整数

 #include <stdio.h>

 int main(void)
{
int i = , value; if((i << ) == 0x0138)
printf("YES!\n");
else
printf("NO!\n"); value = i + 0x0138;
printf("value = %d\n", value); return ;
}

输出结果:

$ ./test
YES!
value = 390
$

从输出结果可以看出,十进制数据与十六进制数据可以直接进行运算,而不需要经过转换。

另外,C语言中的整数有多种形式,二进制数、八进制数、十进制数、十六进制数、字符('A')都是整数,可以使用任何一种形式,或者在任何形式的整数之间进行整数运算。

5、循环结构、switch结构中的break语句

 #include <stdio.h>

 int main(void)
{
enum color {yellow, green, red, black};
enum color bird = red; while(){ switch(bird){
case yellow:
printf("the bird is yellow!\n");
break;
case green:
printf("the bird is green!\n");
break;
case red:
printf("the bird is red!\n");
break;
default:
printf("the bird is black!\n");
break;
} printf("use a break to get out of while!\n");
break;
} printf("we are now at outside of while loop!\n"); return ;
}

输出结果:

$ ./test
the bird is red!
use a break to get out of while!
we are now at outside of while loop!
$

从输出结果可以看出:switch中的break只对switch结构有用,对更外层的while循环无用;while循环中break语句可以跳出while循环。

因此,我们有如下结论:

1、switch结构并非循环结构,遇到break则不再执行该结构中剩下的语句;
2、break语句可以跳出当前的循环结构(一层)。

6、结构体的存储空间

 #include <stdio.h>

 typedef struct {
unsigned request;
unsigned len;
unsigned char data[];
}rms_message_t; int main(void)
{
printf("sizeof(unsigned) = %d\n", sizeof(unsigned));
printf("sizeof(unsigned char) = %d\n", sizeof(unsigned char));
printf("sizeof(rms_message_t) = %d\n", sizeof(rms_message_t)); return ;
}

输出结果:

$ ./test
sizeof(unsigned) = 4
sizeof(unsigned char) = 1
sizeof(rms_message_t) = 8
$

C语法简单测试的更多相关文章

  1. TODO:Golang UDP连接简单测试慎用Deadline

    TODO:Golang UDP连接简单测试慎用Deadline UDP 是User Datagram Protocol的简称, 中文名是用户数据报协议,是OSI(Open System Interco ...

  2. .net orm比较之dapper和Entity Framework6的简单测试比较

    .net orm比较之dapper和Entity Framework6的简单测试比较

  3. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(37)-文章发布系统④-百万级数据和千万级数据简单测试

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(37)-文章发布系统④-百万级数据和千万级数据简单测试 系列目录 我想测试EF在一百万条数据下的显示时间! ...

  4. ORACLE 数据库简单测试

    ORACLE 数据库简单测试 操作系统:Windows 7 – ORACLE:oracle database 10.2.0.4 一.目的 测试 启动监听程序.数据库  非同一个用户的情况,用户是否可以 ...

  5. Javascript的简单测试环境

    在<JavaScript忍者秘籍>2.4测试条件基础知识中,作者给出了一个精简版的assert和assert组的实现,对于初学者而言,这无疑是一个很好的例子,既让我们得到了一个好用的小工具 ...

  6. struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)

    为了之后学习的日子里加深对框架的理解和使用,这里将搭建步奏简单写一下,目的主要是方便以后自己回来脑补: 1:File--->New--->Other--->Maven--->M ...

  7. struts2+hibernate+spring配置版框架搭建以及简单测试(方便脑补)

    为了之后学习的日子里加深对框架的理解和使用,这里将搭建步奏简单写一下,目的主要是方便以后自己回来脑补: 1:File--->New--->Other--->Maven--->M ...

  8. [20190423]简单测试latch nowilling等待模式.txt

    [20190423]简单测试latch nowilling等待模式.txt --//我对这个问题的理解就是如果参数willing=0,表示无法获取该latch,直接退出,再寻找类似的latch.--/ ...

  9. Javascript学习-简单测试环境

    Javascript学习-简单测试环境 在<JavaScript忍者秘籍>2.4测试条件基础知识中,作者给出了一个精简版的assert和assert组的实现,对于初学者而言,这无疑是一个很 ...

随机推荐

  1. 近视BFC

    首先按照常规解释一下名词,BFC(Block formatting context)直译为"块级格式化上下文".一个独立的渲染区域,只有Block-level box参与, 它规定 ...

  2. H5外包团队 MUI文档技术资料大全

    HTML5+ API缓存:http://www.dcloud.io/docs/api/zh_cn/cache.html h.js:http://www.hcoder.net/h vue.js:http ...

  3. static属性和方法

    static属性作为公共属性,可以通过类名称直接调用. static属性可以在没有实例化对象时使用. 非static属性必须在实例化对象产生后才可以使用. static方法也可以在没有实例化对象时由类 ...

  4. .bat批处理启动redis

    背景: 最近,公司的项目开发,需要用到Redis,然而每天都需要到d盘下面的去启动redis很烦, 我是我就想写一个.bat启动文件放在桌面上,这样每天只要在桌面上点以下redis的bat文件就可以启 ...

  5. 关于两栏布局,三栏布局,一级点击三角触发select的onchange事件问题

    首先看这样一个效果:,这个截图来自移动端的列表的一整行,在这个效果当中,存在两个技术点,首先选择祝福卡这个宽度是一定的,右边的部分,宽度随着手机屏幕的宽度而自适应,再一个技术点就是点击最右侧向下箭头, ...

  6. LINQ to Entities 不识别方法“System.DateTime AddDays(Double)

    今天本想在linq里按照时间筛选一下超时的数据,一共两个字段FeedBackTime(计划反馈时间).EndTime(实际反馈时间).需求是这样的,查找数据库里所有EndTime大于FeedBackT ...

  7. python-*args和**kwargs作用和区别

    1. *args 不定长的参数:*args 无论你传递一个参数还是二个还是多个都可以.(*args传入的是无命名参数,例如:add(1,2,3,4,5)存储的是元祖)args可以自定义其他名称 def ...

  8. 小程序md5加密

    function md5(string) { var x = Array(); var k, AA, BB, CC, DD, a, b, c, d; , S12 = , S13 = , S14 = ; ...

  9. SpringBoot关于SpringDataJpa中findOne()方法报错问题

    问题描述: 首先用的SpringDataJPA的1.11版本,可以使用findOne()方法根据id查询 然后我使用了2.0.5版本,发现findOne()方法报错了,不能用来当作根据id查询了. 当 ...

  10. C语言 九九乘法表

    #include <stdio.h> #include <stdlib.h> #include <conio.h> int main() { int i,j,k; ...