Unable to use pointer as used normally. While executing **

int a = 3; printf("%d", &a);

** This should print address of variable a. But it gives an format specifier error.


It turns out the cs50 c compiler uses %p as a format specifier for pointers. While, usually even for pointers normal format specifiers are used as with normal variable.

  • I wouldn't necessarily say that this is an idiosyncrasy of clang; it's just that the default warning level for at least one other major compiler (gcc) doesn't complain about using pointers where an int is expected. If you compile with gcc -Wall, you will also see a warning. – Levi Roth Feb 7 '17 at 20:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .