0

When I goes to the part of utilizing the argv argument from c main method, I found something unusual, I'm not sure someone would encounter this and think about it:

#include <stdio.h>
int main(int argc, char *argv[]){
   char *s = "hello,world";
   printf("%p\n", s);
   s++;
   printf("%p\n", s);
   printf("%p\n", argv);
   argv++;
   printf("%p\n", argv);
}

A very simple c snippet, it is going to print info about argv argument from main; Here is the result in my machine:

0x55c2582f2764
0x55c2582f2765
0x7ffddf3cff48
0x7ffddf3cff50

From the knowledge I learned from this book, I expect it to output something like this:

0x55c2582f2764
0x55c2582f2765
0x7ffddf3cff48
0x7ffddf3cff59

but the output differs, all I can think of is for s, it is pointing to a character, a character takes up 1 byte, so it is expected, but for the latter one, the pointer value increments by 1, why the memory address altered 8 bytes?? such an unusual situation, could anyone share some ideas? many thx!

Thomas
  • 97
  • 1
  • 8
  • [Why does incrementing a void pointer by 1 moves one byte ahead but it's 4 bytes for an integer pointer, 8 for double?](https://stackoverflow.com/q/16336757/995714) – phuclv Apr 02 '21 at 10:45
  • s points to char. What does argv point to? – stark Apr 02 '21 at 10:56

0 Answers0