Hi gurus, what does const char*argv[] means what is actually happening here ?
I have encountered another example in our site explaining difference between char const*p2= "mary" and char*const p1 = "john",
please explain.
I'm not sure how clear I will be able to make this, but I'll give it a try (note this is somewhat simplified):
char* would be a pointer to a char.
const char* is a pointer to a constant char, meaning the char in question can't be modified.
char* const is a constant pointer to a char, meaning the char can be modified, but the pointer can not (e.g. you can't make it point somewhere else).
For the sake of completion: const char* const would be a constant pointer to a constant char, meaning neither the char, nor the pointer, can be modified.
The argv[] is defining an array, so as for your first question const char* argv[] means an array of char pointers within which the chars are constant, meaning they can't be modified. Even more simply put, it's an array of strings that you can't change.
There's more that I can say here about the relation between pointers and arrays, as well as my usage of the word "can't", but I'm afraid it may be too much information too quickly. Hope I was able to answer your questions.
usually that argv[] in main's parameter, use to store parameter that given to program,
for example you run a program called show.exe and want to pass a "name" directly to your program
So it'll looks like
show.exe name
When the program run, argv[0] will be the path of the program in cstring ex:"C:/users/user/desktop/show.exe" and argv[1] will be string "name"
And why const I think it'll prevent the given parameter from changing
Oh and char*argv[] is 2 dimensional array it same as char argv[][] or char**argv