Solved

Why pointer to pointer?

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert image to byte array 8 209
Intel debugger, idb, only seeing .c and .h, but no .f90 1 371
List out all word 7 318
How to programmatically differentiate between C and Java 10 204
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops 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.

829 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