Start New Discussion within our Software Development Community

Could you please tell pictorially difference bw these 2 codes(o/p is same) and suggest any source where i can once in for all resolve doubts in pointer to pointer problems except "K&R in ANSI C"

#include <stdio.h>
   #include <string.h>
 void pointer(char**);
   void main()
{
char *p[]={"name","fame","claim"};

pointer(p);
}
void pointer(char **a)
{int i=0;
while(a[i]!=NULL)
{

printf("\nstring%d is:%s \n",i,a[i]);
i++;
}
}

or

#include <stdio.h>
   #include <string.h>
 void pointer(char**);
   void main()
{
char *p[]={"name","fame","claim"};

pointer(&p);
}
void pointer(char **a)
{int i=0;
while(a[i]!=NULL)
{

printf("\nstring%d is:%s \n",i,a[i]);
i++;
}
}

The second program is wrong because line 8 is not passing a pointer to pointer, but pointer to pointer to pointer, which means that function pointer should have three stars, not two.

but y its producing a same output thats actually confusing me there should be some garbage o/p but prog is running fine
well i'm compiling it with turbo c what changes i should make to it to compile on gcc

Is it the code with which you have doubt or you don't understand pointer to pointer concept??

This article has been dead for over six months. Start a new discussion instead.