我在练习8下面的代码被写入以下cLearnthehardway,我有2个问题大小和数组在C
- 同时打印和整数它用来%ld的打印他们不要%d!
- 打印区域[10] //超出范围打印0!为什么不拿给我一个错误,而它的valgrind通过(6erros)
#include<stdio.h>
int main(int argc,char *argv[])
{
int areas[]={10,12,13,14,20};
char name[]="Zed";
char full_name[]={'Z','e','d',' ','A','.',' ','S','h','a','w','\0'};
printf("The size of an int: %ld\n", sizeof(int));//why didn't we use %d instead of %ld(*)
printf("The size of areas (int[]):%ld\n",sizeof(areas));//*
printf("The number of ints in areas : %ld\n",sizeof(areas)/sizeof(int));//*
printf("The first area is %d, the second area is %d\n",areas[0],areas[1]);//Printed areas[10]=0!!
printf("The size of a char is: %ld\n",sizeof(char));//*
printf("The size of name(char[]) is:%ld\n",sizeof(name));//*
printf("The number of chars is : %ld\n",sizeof(name)/sizeof(char));//*
printf("the size of FULL NAME (char[]) is:%ld\n",sizeof(full_name));//*
printf("The number of chars in full name is %ld\n",sizeof(full_name)/sizeof(char));//*
printf("name=\"%s\" and full name =\"%s\"\n",name,full_name);// what is \"%s\" \ is an ESCAPE
return 0;
}
问题已经被答案解决,我选择了完美的一个:) – 2014-11-21 13:18:31