volation关键字
#include
#include
using namespace std;
int main()
{
const volatile j=10;
cout<<"j"<
return 0;
}
变量的类型长度
#include
using namespace std;
int main()
{
int i=0;
int j=-0;
int k=-20;
unsigned u=10;
printf("i=%0x\n",i);
printf("j=%0x\n",j);
printf("k=%0x\n",k);
printf("u=%0x\n",u);
printf("k+u=%d\n",k+u);
return 0;
}
测试机器的大小端
#include
int check() //the system is small_endian
{
union
{
int i;
char ch;
}u;
u.i=1;
return (u.ch==1);
}
int main()
{
printf("%d\n",check());
return 0;
}
除法
#include
int main()
{
char *p =NULL;
printf("p %d\n\n",sizeof(p)); //4
printf("*p %d\n\n",sizeof(*p)); //1
return 0;
}
逗号表达式
#include
int main()
{
int i;
for(i=0,printf("first = %d\n",i);i<10;i++,printf("third = %d\n",i))
{
printf("fourth = %d\n",i);
/*if(i>=10)
break;*/
}
return 0;
}
宏定义的大小
#include
#include
using namespace std;
#define X 3
#define Y X*2
#undef X
#define X 2
int main()
{
int z=Y;
printf("%d",z);
return 0;
}
混合自加自减运算的顺序
#include
int main()
{
int i=3;
int b = 4;
int k = i+++b;
printf("%d\n",k);
printf("%d\n\n",i);
int i1=3;
int b1 = 4;
int k1 = ((i1++))+b1;
printf("%d\n",k1);
printf("%d\n\n",i1);
return 0;
}
自加自减
#include
int main()
{
/*int i=3;
int k;
k = (i++) + (i++) + (i++); //k=9
printf("%d\n",k);
printf("%d\n",j);
printf("%d\n",i);*/
/*int i=3;
int j =(i++,i++,i++);
printf("%d\n",j); //j=5
printf("%d\n",i); //i=6
*/
/*int i = 3;
int k = (++i)+(++i)+(++i); //16
printf("%d\n",k); */
/* int i ;
for(i=0;i<10;)
{
printf("%d ",i);
i++;
} */
int i ;
for(i=0;i<10;i++)
{
printf("%d ",i);
}
printf("%d",i);
return 0;
}
枚举变量的大小
#include
enum Color
{
}color;
int main()
{
printf("%d\n",sizeof(color));
return 0;
}
“\”连接符
#include
#include
using namespace std;
#def\
ine CHAR "csjskdjso"
#defin\
e M 5
int main()
{
char p[] = CHAR;
cout<
return 0;
}
内存对齐
#include
struct TestStruct1
{
char c1;
short s;
char c2;
int i;
};
main()
{
struct TestStruct1 a;
printf("c1 %p, s %p, c2 %p, i %p\n",
(unsigned int)(void*)&a.c1 - (unsigned int)(void*)&a,
(unsigned int)(void*)&a.s - (unsigned int)(void*)&a,
(unsigned int)(void*)&a.c2 - (unsigned int)(void*)&a,
(unsigned int)(void*)&a.i - (unsigned int)(void*)&a);
printf("%d\n",sizeof(TestStruct1));
printf("%d",sizeof(short));
return 0;
}
无符号整数
#include
int main()
{
unsigned int i;
for(i=9;i>=1;i--)
printf("%u\n",i);
printf("%u\n",i);
return 0;
}
预处理
#include
#define BSC //
//#define BMC /*
//#define EMC */
BSC my single-line comment
//BMC my multi-line comment EMC
int main()
{
return 0;
}
c语言深度剖析的问题
38页 1.12
const volatile int i=10;
是成立的,主要因为 const是指不允许程序来修改变量,而volatile指出此变量可能被比如操作系统、硬件或者其它线程等修改
,两者针对的内容不同。
extern const int i; //正确的声明
extern const int j=10; //错误!只读变量的值不能改变。