Hey I am trying to understand pointers and I noticed something which causes undefined behavior in my program In first case when I decay pointer to q1 to NULL everything is fine but when I decay pointer *q1 to NULL the terminal does not show anything . What is going wrong?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main ()
{
char *p[11]={"vasilis","loukas","vasilis","vasilis","giorgos","makis","vasilis","nikos","makis","nikos"};
char **p1;
char**d1;
char**q1;
q1=NULL;
p1=&p[0];
d1=&p[1];
/******Count words*********/
int count=0;
for(p1=&p[0] ; *p1 ; p1++)
{
count++;
}
printf("\nthe number of words : %d" ,count);
return 0;
}
second case :
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main ()
{
char *p[11]={"vasilis","loukas","vasilis","vasilis","giorgos","makis","vasilis","nikos","makis","nikos"};
char **p1;
char**d1;
char**q1;
*q1=NULL;
p1=&p[0];
d1=&p[1];
/******Count words*********/
int count=0;
for(p1=&p[0] ; *p1 ; p1++)
{
count++;
}
printf("\nthe number of words : %d" ,count);
return 0;
}