where are static values stored?
Given the following code:
Code:
#include <stdlib.h>
#include <stdio.h>
int do_something(char *);
int
main(int argc, char *argv) {
char *c = malloc(sizeof(char));
*c = 'c';
do_something(c);
do_something(NULL);
return 0;
}
int
do_something(char *value) {
static char *c;
if (value) {
c = value;
}
printf("%c\n", *c);
return 0;
}
Is the address of the variable c inside do_something stored on the heap, stack, or in a different location in memory? How does the program know to reference the same address/value when the function is called a second time?