Thursday, July 30, 2009

What is **pArgv in C++?

I am taking a intermediete programming course studying the C++ programming language and part of or discussion is to say what **pArgv means. I know it is a pointer, but I am not sure what it means and what the two ** means. I have to do some research, but I cannot seem to find out what this means on the internet.

What is **pArgv in C++?
**pArgv is pointer to pointer.


You had not mentioned the type of the variable it points to:





int **p;





will declare pointer to pointer to integer.
Reply:As noted above **pArgv is a pointer to pointers to char.


But more that that it is to pointer to the information that is passed in via command line arguements.





Your program always has a main() of the form:


int main( int argc, char *argv[])





argv[0] is the name of the program that is running.


argv[1]...argv[argc-1] are the tokens from the command line.





If your command line is:





C:\myprogram.exe file1.dat file2.dat





then argc = 3


argv[0] = "myprogram.exe"


argv[1] = "file1.dat"


argv[2] = "file2.dat"





You can see sample code at the Microsoft site linked to below.
Reply:This is actually dereferencing a pointer value through a pointer. (The ** signifies that argv is a pointer to a pointer.)





The argv vector is actually an array of pointers to strings. The array itself (which can be dereferences using [], can also be dereferences like a pointer), which points to a list of pointers.





The first '*' pulls out the address of the string from the argv array, the second '*' dereferences the address of the string.





In some code, you'll see it written as "char **argv", and in others, you'll see "char *argv[]" which can be used interchangeable.





In a nutshell, argv is pointer to an array of pointers.

land survey

No comments:

Post a Comment