• C

Newbie

Hello experts,

I have a few question that come across my head when I browse thru a smalll program regarding pointers..


From my understanding a pointer is declare as :
     char *ptr;

but I saw a special case where some programmer declare as :
   char **ptr;

I just hope u can explain to me about this type of pointer what it means and show me some small example (if u can I will appreciate it).

Thanx

dekoayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BudVVeezerCommented:
char **p;  is a pointer to a pointer.  This might help a bit:

char c  this is a byte in memory that stores a char.

char *c  this is a pointer to a memory location where a char resides.  You need to dereference that pointer to access the variable.

char **c  this is a pointer to a pointer to a memory location. You need to dereference this variable twice also.  Keep in mind, this COULD be a pointer to a string(which is a pointer to a block of chars in memory).

If you see it being used in a function call, then it is most likely a pointer to a string.  Many programmers use **c(also known as handles) or single pointers when they want to fill a variable.  So it starts out with blank, the function gets called and when it returns, there is something in there.  So you would declare as follows:

char *String = "";

MyFunc(&String);
printf(String);

Hope this helps!

~Aaron
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlexVirochovskyCommented:
dekoay, do you want article about
pointers? You can get it from
http://www.snippets.org/ (as part
of zip file)
or i can send you (write you EMail)
0
dekoayAuthor Commented:
BudVWeezer(Aaron),

Thanks for the explanation regarding this pointer... However, does this only works with gcc compiler(in unix) or this is an ANSI standards ?

However, I'm quite understanding after the exaplnation....


Thanks again

Dekoay
0
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

BudVVeezerCommented:
this is an ANSI standard.  I suppose if you got super bored you could do something like this:

char *****c;

and deal with it from there...but don't, or someone will NOT like you're code.  ;-)  Basically, you can add as many pointers to something as you wish(I don't think there's a limit)...

~Aaron
0
dekoayAuthor Commented:
hello Bud,

Thanx for the conclusion
0
BudVVeezerCommented:
no problem, it's called earning the points.  =)

~Aaron
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.