lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

const char *const *Args,

Wed Sep 30, 2015 5:57 am

const char *const *Args,

what is this? Args is pointer to what? why there's 2 *there?

User avatar
RogerW
Posts: 286
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: const char *const *Args,

Wed Sep 30, 2015 8:00 am

I think Args is a const pointer to a const pointer to char.

User avatar
jeanleflambeur
Posts: 157
Joined: Mon Jun 16, 2014 6:07 am
Contact: Website

Re: const char *const *Args,

Wed Sep 30, 2015 8:14 am

Args is a const array of const C strings.
*Args is a const C string.
**Args is a const char.

Since a C string is a pointer to char and an array can be expressed as a pointer to its first element, Args can be expressed as char const* const*.
To iterate through the array, increment Args. To access C string Args is currently pointing at, dereference Args.

Some random google result explaining this in more depth:
http://c.learncodethehardway.org/book/ex10.html

beta-tester
Posts: 1305
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: const char *const *Args,

Wed Sep 30, 2015 8:44 am

lilzz wrote:what is this? Args is pointer to what? why there's 2 *there?
char* => pointer to char => a string
char** => pointer to an array of pointer of char => array of strings
char*** => array of array of strings
...

similar to char[], char [][], char [][][], ...
or
similar to char*, char* [], char *[][], ...

"Args" is an array of argument strings
in your special case an constant array of constant strings. the array is const and the strings are const.
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

User avatar
DougieLawson
Posts: 36897
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: const char *const *Args,

Wed Sep 30, 2015 6:02 pm

Get a copy of Kernighan and Ritchie and read that from cover to cover before asking your next pointless question about the C language. You'll reap rewards from doing that, it will be the best $50 you ever spend.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “C/C++”