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. Demo整合

    1.图片上传:  https://github.com/842549829/WebUploader 2.百度编辑器: https://github.com/842549829/Ueditor 3.安卓 ...

  2. VGG

    2019-04-08 13:30:58 VGG模型是2014年ILSVRC竞赛的第二名,第一名是GoogLeNet.但是VGG模型在多个迁移学习任务中的表现要优于googLeNet.而且,从图像中提取 ...

  3. UNDO -- Concept

     Undo data Records of the actions of transactions, primarily before they are committed. The database ...

  4. [redis] redis 命令

  5. vue父子组件的传值总结

    久违的博客园我又回来了.此篇文章写得是vue父子组件的传值,虽然网上已经有很多了.写此文章的目的就是记录下个人学习的一部分.接下来我们就进入主题吧! 在开发vue项目中,父子组件的传值是避免不掉的. ...

  6. spring RedisTemplate的使用(一)--xml配置或JavaConfig配置

    1.xml配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="h ...

  7. docker 启动 nginx 服务

    docker run -d -p 80:80 --restart=always nginx:latest 参数说明: run 启动某个镜像 -d 让容器在后台运行 -p 指定端口映射,宿主机的80端口 ...

  8. 为什么Java的main方法必须是public static void?

    一. void 如下,像C, C++一样,将返回值类型改为int,再返回一个0,虽然编译通过,但是运行时会报错. 找到一种可理解的解释:方法的副作用和返回值类型.(http://www.cnblogs ...

  9. 【数据结构】运输计划 NOIP2015提高组D2T3

    [数据结构]运输计划 NOIP2015提高组D2T3 >>>>题目 [题目描述] 公元 2044 年,人类进入了宇宙纪元.L 国有 n 个星球,还有 n−1 条双向航道,每条航 ...

  10. <a> 标签详解

    一.<a> 标签的样式 在所有浏览器中,链接的默认外观是: 未被访问的链接带有下划线而且是蓝色的 已被访问的链接带有下划线而且是紫色的 活动链接带有下划线而且是红色的 我们可以使用CSS伪 ...