ProgrammingEasyWipro · Capgemini pattern
Which printf format specifier is meant for printing a pointer value (an address)?
- A. %f
- B. %p
- C. %c
- D. %d
Correct answer: B. %p
%p prints a void * address in an implementation-defined form (usually hexadecimal). Printing a pointer with %d is undefined and breaks on 64-bit systems where pointers are wider than int.
More C Programming questions
- What is printed? c printf("%d", 10 / 3 3);
- What is printed? c int a = 5, b; b = a++ + 10; printf("%d %d", a, b);
- What is printed? c char s[] = "placement"; printf("%zu %zu", sizeof(s), strlen(s));
- What is printed? c int arr[] = {10, 20, 30, 40}; int p = arr; p += 2; printf("%d", p);
- What does f(4096) return? c int f(int n) { if (n == 0) return 0; return n % 10 + f(n / 10); }
- What is printed? c printf("%d %d %d", 12 & 10, 12 | 10, 12 ^ 10);