I know at runtime, environ is a global pointer variable which ended up stored in the data section. envp is a local variable defined in the main, so it stores in the stack or top of the stack. Correct me if I am wrong.
But the question is, where is the actual string information these two environment stored? Both in the stack?
I attach the two code segments that these two environment variables are used.
for environ:
#include <stdlib.h>
#include <stdio.h>
extern char **environ;
int main(int argc, char **argv)
{ char **env_variable_ptr;
env_variable_ptr = environ;
while (*env_variable_ptr != NULL)
{ printf("%s\n", *env_variable_ptr);
env_variable_ptr++;
}
printf("\n");
}
For envp:
int main(int argc, char **argv, char **envp){
while(*envp != NULL){
printf("%s\n", *envp);
envp++;
}
printf("\n");
}