字符串指针比较

 1 char str1[] = "123";
 2 char str2[] = "123"; //1
 3 const char str3[] = "123";
 4 const char str4[] = "123"; //1
 5 char *str5 = "123";
 6 char *str6 = "123"; //0
 7 const char *str7 = "123";
 8 const char *str8 = "123"; //0
 9 cout << (str7!= str8) << endl;
10 cout << static_cast<void*>(str5) << endl; //输出字符指针地址
11 cout << static_cast<const void*>(str7) << endl;
12 printf("%p,\n",str8);

double*转换为int*后移动距离

1 A *p = new A;
2 double *p2 = new double[2];
3 p2[0] = 1; p2[1] = 2;
4 int *q = (int*)(p2);
5 printf("%p,%p,%p\n", q, q + 1, p2);
6 printf("%d,%d", q[0], q[1]);

c旧式转换 double *可以转换为int*,用static_cast<int *>会直接提示语法错误,都不用编译报错,所以 C++风格的转换更安全;

转载于:https://www.cnblogs.com/hchacha/p/7530711.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值