Why would such checking *(string + i) don't pass after all strings are printed?
The output of printf("%p", string + i + 1); definitely shows string + i + 1 isn't NULL.
I've tried this code several times with several quantity of strings.
Maybe some of C guru can give answer to this? Thanks in advance. :-)
The code:
#include <stdio.h>
int
main(void)
{
size_t i;
char *string[] = {
"Hey, baby!",
"How are ya?",
"What the heck is going on in here?"
};
for (i = 0; *(string + i); ++i)
{
printf("%s\t%p\n", *(string + i), string + i);
}
printf("%p", string + i + 1);
return 0;
}
The output:
[aenry@MintK50ID 2]$ ./test
Hey, baby! 0x7fff691978e0
How are ya? 0x7fff691978e8
What the heck is going on in here? 0x7fff691978f0
0x7fff69197900%
[aenry@MintK50ID 2]$ gcc -v
...
gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu9)
--------Edit: It turned out, this is really junk code and somehow only gcc compiles it in a way it works. UB nuff said. Thanks, guys.