C newbie malloc question
Posted
by roufamatic
on Stack Overflow
See other posts from Stack Overflow
or by roufamatic
Published on 2010-05-07T23:46:37Z
Indexed on
2010/05/07
23:58 UTC
Read the original article
Hit count: 223
Why doesn't this print 5
?
void writeValue(int* value) {
value = malloc(sizeof(int));
*value = 5;
}
int main(int argc, char * argv) {
int* value = NULL;
writeValue(value);
printf("value = %d\n", *value); // error trying to access 0x00000000
}
and how can I modify this so it would work while still using a pointer as an argument to writeValue
?
© Stack Overflow or respective owner