Code:
int main(int argc,char *argv[])
{
printf("%p\n",argv); // location of argv
printf("%p\n",argv[0]); // contents of argv[0] (points to name of program)
printf("%p\n",argv[1]); // contents of argv[1] (points to argument 'name')
printf("%p\n",argv[2]); // contents of argv[2] (points to argument 'arg')
printf("%s\n",argv[0]); // %s dereferences the pointer in argv[0] and prints the name of the program
printf("%s\n",argv[1]); // %s dereferences the pointer in argv[1] and prints 'name'
printf("%s\n",argv[2]); // %s dereferences the pointer in argv[2] and prints 'arg'
return 0;
}
program output (with comments)
Code:
00423380 location of the argv array
00423390 contents of first element of argv
004233AE contents of second element of argv
004233B3 contents of third element of argv
e:\home\dh0072\x1.exe
name
arg
memory dump
Code:
argv[0] argv[1] argv[2]
x00423380 [90 33 42 00] [ae 33 42 00] [b3 33 42 00] 00 00 00 00 .3B.®3B..3B.....
0x00423390 65 3a 5c 68 6f 6d 65 5c 64 68 30 30 37 32 5c 78 e:\home\dh0072\x
0x004233A0 5c 44 65 62 75 67 5c 78 31 2e 65 78 65 00 6e 61 \Debug\x1.exe.na
0x004233B0 6d 65 00 61 72 67 00 fd fd fd fd ab ab ab ab ab me.arg.