http://blog.csdn.net/ameyume/article/details/5893686 2010 - typedef struct _st{
- int a;
- int b;
- char c;
- }st;
-
- struct _struTest
- {
- short sh;
- long ln;
- }struTest;
-
- int _tmain(int argc, _TCHAR* argv[])
- {
-
- char arr[] = "123456789";
- char *p1 = "12345";
- char *p2 = arr;
- int iNum = 10;
-
- printf("sizeof(arr) = %d/n", sizeof(arr)); // sizeof(arr) = 10, including the end charactor '/0'
- printf("strlen(arr) = %d/n", strlen(arr)); // strlen(arr) = 9
- printf("sizeof(p1) = %d/n", sizeof(p1)); // sizeof(p1) = 4
- printf("sizeof(p2) = %d/n", sizeof(p2)); // sizeof(p2) = 4
- printf("sizeof(iNum) = %d/n", sizeof(iNum)); // sizeof(iNum) = 4
-
- int a1 = -2147483648, a2 = 2147483647;
- if (a1 > a2) // false
- {
- printf("a1 > a2/n");
- }
-
- if (a1 - a2 > 0) // true
- {
- printf("a1 - a2 > 0/n"); // output a1 - a2 > 0
- printf("a1 - a2 = %d/n", a1 - a2); // output a1 - a2 = 1
- }
-
- printf("sizeof(char) = %d/n", sizeof(char));
- printf("sizeof(short) = %d/n", sizeof(short));
- printf("sizeof(int) = %d/n", sizeof(int));
- printf("sizeof(long) = %d/n", sizeof(long));
- printf("sizeof(st) = %d/n", sizeof(st)); // 字节对齐,以int为准
- printf("sizeof(struTest) = %d/n", sizeof(struTest)); // 字节对齐,以long为准
-
-
-
- system("Pause");
-
- return 0;
- }
32位系统下的输出结果:
sizeof(arr) = 10 // 数组的长度,数组会自动加一个结束符'/0' sizeof(p1) = 4 // 输出的是指针的长度4 sizeof(p2) = 4 // 输出的是指针的长度4 sizeof(iNum) = 4 // 输出的是int型变量的长度4 a1 - a2 > 0 a1 - a2 = 1
sizeof(char) = 1 sizeof(short) = 2 sizeof(int) = 4 sizeof(long) = 4 sizeof(st) = 12 sizeof(struTest) = 8
由输出结果可以知道,判断条件a1 > a2 与a1 - a2 > 0的结果是不一样的。
|