Solved

Why pointer to pointer?

Posted on 2008-10-16
4
197 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

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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

695 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