Saturday, 7 September 2013

suppose char *p = "hello world", so is there any '\0' exist right after the 'd'?

suppose char *p = "hello world", so is there any '\0' exist right after
the 'd'?

#include<stdio.h>
#include<string.h>
int main()
{
char *p = "hello world";
int a = (int)(*(p+strlen(p)+1)); // equal to a=(int)(*p+12)
printf("%d\n", a);
return 0;
}
a is not '\0', why?
#include<stdio.h>
#include<string.h>
int main()
{
char *p = "hello world";
int a = (int)(*(p+strlen(p)+1)); // equal to a=(int)(*p+12)
for(int i=0; p[i]!='\0'; i++)
printf("%c",p[i]);
return 0;
}
return: hello world so, i wonder if '\0' do exist at the end of the string?

No comments:

Post a Comment