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?
This worked:
int* var = malloc(sizeof(int));
while(scanf("%d", var) && *var != 0)
printf("%d \n", *var);
Doing a refresher course on C, glad I did it.
I realized that scanf(&var) is for regular variables, while scanf(var) is for pointers. But completely forgot about the memory, thank you!