1.long long 类型数据在windows机下输入格式控制符为%I64d, 不然用%lld可能出错, 因为%lld这个占位符不是跨平台的。
—————————————-
更新时间:2018/3/9
2.指向结构体指针应用错误代码
#include<iostream>
using namespace std;
struct aa
{
int a;
int *b;
};
struct cc
{
aa *m;
};
int main()
{
cc ne;
int mm[5] = {1};
ne.m -> a = 1;//编译虽然不会报错,但运行可能出错,是比较危险的行为
ne.m -> b = mm;
cout<<ne.m->a<<endl;
cout<<ne.m->b[0]<<endl;
return 0;
}
原因:没有为cc中的m分配内存空间,所以m指向了未知的内存空间的地址。
正确姿势:使用new关键字分配内存空间
#include<iostream>
using namespace std;
struct aa
{
int a;
int *b;
};
struct cc
{
aa *m;
};
int main()
{
cc ne;
int mm[5] = {2};
ne.m = new aa;
ne.m -> a = 1;
ne.m -> b = mm;
cout<<ne.m->a<<endl;
cout<<ne.m->b[0]<<endl;
return 0;
}
结果:程序正常运行。
—————————————-
更新时间:2018/3/24
3. “.c文件”中swithch语句中无法使用const关键字,编译器会报错。