69,382
社区成员
发帖
与我相关
我的任务
分享
// 编译环境mingw5
#include <stdio.h>
int main(int argc, char *argv[])
{
char *p1 = 'a'; // 1.这样能取到地址码? 为什么gcc有警告:warning: initialization makes pointer from integer without a cast
char *p2 = 'b';
char *p3 = "hello"; // 2.这样取地址应该没问题吧?
char *p4 = "world";
printf("%d %d ", p1, p2);
printf("%d %d ", p3, p4);
printf("%d ", sizeof('h'));//3.为什么结果是4 ???
printf("%d ", sizeof("hello"));
return 0;
}
#include <stdio.h>
int main(int argc, char *argv[])
{
char *p1 = 'a'; // 这样是 直接 将 a的 assic 97 作为地址 赋给 p1
char *p2 = 'b';
char *p3 = "hello"; // 这样是将 字符串首地址 赋给p4
char *p4 = "world";
printf("%d %d ", p1, p2);
printf("%d %d ", p3, p4);
printf("%d ", sizeof('h'));// h的 assic 值 作为 int 型 所以4字节
printf("%d ", sizeof("hello"));
return 0;
}
#include <stdio.h>
int main(int argc, char *argv[])
{
char *p1 = 'a'; // 1.这样能取到地址码? 为什么gcc有警告:warning: initialization makes pointer from integer without a cast
char *p2 = 'b';
char *p3 = "hello"; // 2.这样取地址应该没问题吧?
char *p4 = "world";
printf("%d %d ", p1, p2);
printf("%d %d ", p3, p4);
printf("%d ", sizeof('h'));//3.为什么结果是4 ???
printf("%d ", sizeof("hello"));
return 0;
}