Solved

Why pointer to pointer?

Posted on 2008-10-16
4
191 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
Comment Utility
>> 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
Comment Utility
so that it can point to a list of char *
0
 
LVL 6

Accepted Solution

by:
RishadanPort earned 45 total points
Comment Utility
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
Comment Utility


Thanks to all specially for the details.

Regards.
ak
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them 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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now