We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,601 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

help me with pointer to pointer indirection

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++;
}
}
3
Contributors
4
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
5
Views
linkingeek
Newbie Poster
9 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

Ancient Dragon
Achieved Level 70
Team Colleague
32,109 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,575
Skill Endorsements: 68

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

linkingeek
Newbie Poster
9 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

Ancient Dragon
Achieved Level 70
Team Colleague
32,109 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,575
Skill Endorsements: 68

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

versan
Newbie Poster
23 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0757 seconds using 2.67MB