1.
#include <stdio.h> #include <malloc.h> typedef struct _demo { int* pInt; float f; } Demo; int func(int v, int m) { return (v & m != 0); } int main() { Demo* pD = (Demo*)malloc(sizeof(Demo)); int *p[5]; int *f(); int i = 0; i = 1, 2; *pD.f = 0; free(pD); return 0; }
int *p[]; 根据优先级,是一个指针数组.
*pD.f 编译认为是*(pD.f);
a: '点'的优先级高于'*"
b. () 的优先级高于"*".
c. ==和!=高于位操作.
d: == 和!=高于赋值运算
e. 豆号运行是所有运算符中优先级最低的.
h. 算术运行符高于位移运算符号.
2. C语言隐式类型转换.
算术运算式中,低类型转换为高类型
赋值表达式中,表达式的值转换为左边变量的类型
函数调用时,实参转换为形参的类型
函数返回值,return表达式转换为返回值类型
char --->int -> unsigned int -> long -> unsigned long -> double<--- float
short--->
char --->short.
#include "stdafx.h" int main(int argc, char* argv[]) { char c ='c'; short s=0; printf("%d\n",sizeof(c)); printf("%d\n",sizeof(s+c)); printf("%d\n",sizeof(c)); printf("Hello World!\n"); return 0; }
类型转换的XX. #include <stdio.h> int main() { int i = -2; unsigned int j = 1; if( (i + j) >= 0 ) { printf("i+j>=0\n"); } else { printf("i+j<0\n"); } printf("i+j=%d\n", i + j); return 0; }
#include <stdio.h> int main() { int i = -2; unsigned int j = 1; if( (i + j) >= 0 ) { printf("i+j>=0\n"); } else { printf("i+j<0\n"); } printf("i+j=%d\n", i + j); printf("i+j=%hu\n", i + j); printf("i+j=%0x\n", i + j); return 0; }
则打印输出
i+j>=0
i+j=-1
i+j=65535
i+j=ffffffff