I am trying to figure out what will be result of passing argv variable to main in this format. main( int argc, char const * argv ).
I know right way of using it is main( int argc, char const **argv) or main( int argc, char const *argv[]).
Here is my code snippet,
#include <stdio.h> int main( int argc, char const * argv ) { for( int i = 0; i < argc; ++i ) { printf("%s\n", argv[i]); } } Here is output,
$ ./a.exe
..
$ ./a.exe 1
2
....
$ ./a.exe 1 2
2
...
Does it fetch from whatever, argv points? Why does it terminate before even reaching argc.
argvas a buffer of pointers to non-const strings.argv[i]will be acharvalue. In theprintfcall, that will be promoted to anintvalue. However, theprintffunction is expecting a valid pointer to a null-terminated sequence ofcharat that position, not some bogus pointer value.