I’m a a beginner to C.
main() {
int *a-ptr = (int *)malloc(int);
*a-ptr = 5;
printf(“%d”, *a-ptr);
}
The question is: is this guaranteed to print 5?
The answer is : NO, for two reasons:
- you can’t use “-” in the names of variables
- “you didn’t allocate int storage”
I don’t understand that second point. Isn’t the storage allocated with this line?
int *a-ptr = (int *)malloc(int);
So a better version of your code would be: