C pointer question, dereferencing crash
- by skynorth
Why do this work?
int *var;
while(scanf("%d", &var) && *var != 0)
printf("%d \n", var);
While this does not?
int *var;
while(scanf("%d", &var) && var != 0)
printf("%d \n", var);
Doesn't * (dereference operator) give you the value pointed by the pointer? So why does
*var != 0 crash the program, while var != 0 does not?