Solved

Why pointer to pointer?

Posted on 2008-10-16
4
195 Views
Last Modified: 2012-05-05
Hello group,

In a source file I was looking main() function is:

 int main(int argc, char **argv)

why there is **argv rather than *argv?


Regards.
0
Comment
Question by:akohan
4 Comments
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 40 total points
ID: 22735601
>> why there is **argv rather than *argv?

Because that's how it's defined ;)

argv is an array of strings. A string is a char*. Multiple char*'s is char**, just like multiple int's is int*.
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 40 total points
ID: 22735603
so that it can point to a list of char *
0
 
LVL 6

Accepted Solution

by:
RishadanPort earned 45 total points
ID: 22736178
The main idea that you have to understand, is that when you run a program, you may want to pass in a bunch of arguments.

Lets suppose you create a program, and which is named program.exe.

you can run the program like this:

program.exe <argument 0> <argument 1> <argument 2> <argument 3> ..

now in your main function you can access each of these arguments like this:

int main(int argc, char **argv){
   for(int index = 0; index < argc; index++){
      printf("Argument %d is: %s", index, argv[index]);   <-- (argv[index] is a char*)
   }
}
0
 

Author Comment

by:akohan
ID: 22736451


Thanks to all specially for the details.

Regards.
ak
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question