I want ask about define array of pointers in C. In following code, I define two pointers to char and then I assign each pointer to return from strtok function.
#include<stdio.h>
#include<string.h>
main()
{
char *s[2], string[]="hehe hihi keke kaka huhu hixhix",delimit[]=" ";
int i=0;
s[i]=strtok(string,delimit);
while( s[i]!=NULL )
{
printf("i=%d -> %s \n",i,s[i]);
++i;
s[i]=strtok(NULL,delimit);
}
}
This is output:
i=0 -> hehe
i=1 -> hihi
i=2 -> keke
i=3 -> kaka
i=4 -> huhu
i=5 -> hixhix
So, I just define two pointers but the code run with no error when i is greater then 1.
Why it work well even when I just define less number of pointers than necessary pointers (eg: 6 or greater) ?
thanks for reading!