LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-06-2011, 10:37 AM   #1
smag
LQ Newbie
 
Registered: May 2011
Location: Linux land
Distribution: Arch linux
Posts: 26

Rep: Reputation: 11
Question What's char**?


Code:
char* Var;
is a pointer but what's
Code:
char**
?
 
Old 10-06-2011, 10:44 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
char* is a pointer to a char, char** is a pointer that points to a pointer to a char.
 
1 members found this post helpful.
Old 10-12-2011, 05:28 AM   #3
ArthurSittler
Member
 
Registered: Jul 2008
Distribution: Slackware
Posts: 124

Rep: Reputation: 31
Most common use of char** type is dereferencing an array of strings. For example, the days of the week is an array of strings.
 
Old 10-13-2011, 06:49 AM   #4
smag
LQ Newbie
 
Registered: May 2011
Location: Linux land
Distribution: Arch linux
Posts: 26

Original Poster
Rep: Reputation: 11
Quote:
Originally Posted by TobiSGD View Post
char* is a pointer to a char, char** is a pointer that points to a pointer to a char.
Thanks!
 
Old 10-13-2011, 07:00 AM   #5
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
char* typically points to an array of byte-wide characters (a string).
char** typically points to an array of strings. This is used as the second parameter to main(), for example, to point to the command line argument strings.

…though TobiSGD's description is more general (and accurate).

Also, correct me if I'm wrong, but I think you can nest pointers an arbitrary number of levels, i.e. you can have a pointer to a pointer to a pointer (e.g. char***), right? Not that this would be necessary most of the time, but in theory I don't see why it shouldn't be possible… :-\

Last edited by MrCode; 10-13-2011 at 07:18 AM. Reason: point to, not "store", WTF
 
1 members found this post helpful.
Old 10-13-2011, 09:30 AM   #6
smag
LQ Newbie
 
Registered: May 2011
Location: Linux land
Distribution: Arch linux
Posts: 26

Original Poster
Rep: Reputation: 11
Ok, thanks for the replies.
 
Old 10-13-2011, 09:39 AM   #7
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
C and C++ types don't distinguish a pointer to something vs. a pointer to the first something in an array of something's.

So char* x; declares x as a pointer to char, but doesn't distinguish whether it points to an isolated char or a "C string", which is an array of char's.

So char** y; declares y as a pointer to pointer to char, but that allows multiple possibilities.
Does y point to a single char* or an array of them.
Does *y (or each of y[i]) point to a single char or an array of them.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I point a char pointer to a part of another char array? trist007 Programming 8 11-06-2010 07:56 PM
invalid conversion from `const char*' to `char' error holystinken Programming 7 11-23-2009 06:01 PM
error: invalid conversion from const char* to char* Dahakon Programming 1 08-31-2009 09:33 AM
If I get invalid conversion from `const char*' to `char' what should I be lookin for? RHLinuxGUY Programming 5 03-12-2006 10:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration