Solved

Why pointer to pointer?

Posted on 2008-10-16
4
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Handling string inputs in C/Linux 23 200
xamarin c# deserialize Json containing nested object 2 173
What is sub-make ? 2 101
Exchange 2013 fills up C drive with logs 4 23
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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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.

740 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