#include
#include <stdio.h>
int main() {
int a=0, b=0, c=0, d=0;
if (a == 0) {
b = 2;
c = 2;
} else {
d = 3;
}
printf("%d,%d,%d,%d",a,b,c,d);
return 0;
}
if不加括号只能走下面一句。else没有if先匹配
如果结构体中包含有指针类型,那么复制就有两种:
浅复制代码。
char *aname = (char*)malloc(10*sizeof(char));
strcpy(aname, "test1");
Student a = {1001, aname, true};
Student b;
b = a;
浅复制效果。
test1.name:test1 test2.name:test1
test1.name ptr:0000000000736AB0 test2.name ptr:0000000000736AB0
深复制代码。
char *aname = (char*)malloc(10*sizeof(char));
strcpy(aname, "test1");
Student a = {1001, aname, true};
Student b;
b = a;
b.name = (char*)malloc(10*sizeof(char));
strcpy(b.name, a.name);
深复制效果(看地址的倒数第二位,是不同的)。
test1.name:test1 test2.name:test1
test1.name ptr:0000000000BD6AB0 test2.name ptr:0000000000BD6AD0