I need some help in understanding how the memory allocation is performed in this situation.
char someStringPointer[100] = "hello world";
char *argv[3];
argv[0] = "echo";
argv[1] = someStringPointer;
argv[2] = NULL;
Since I'm not allocating memory, everything will be on the stack, so no heap memory is allocated here.
But I'm not sure how the memory is allocated on the stack. Every pointer is 8 bytes, so let's say that argv is at (in octal)100.
so argv[0] is at 100, argv[1] is at 101 and argv[2] is at 102.
argv[0] will now point to a block of 5 bytes which holds the characters "echo\0" when I'm using the assignment operator '=' it's allocating memory directly on the stack based on the length of the string? (sequence of chars more precisely).
argv[1] will point to wherever someStringPointer was allocated.
argv[2] I'm not sure, I'm guessing it's not pointing anywhere and set to null.
I am keen to understand what the memory looks like here.
argvis on the stack. It contains 3 pointers. Each of them points to a string allocated somewhere else (string literal in one case, an array of chars in another), or set to NULL.