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

Change second example program like this: pointer(&p[0]); Also add NULL to this line: char *p[]={"name","fame","claim",NULL};

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.