ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
#define N 5
#undef N
#define N 10
int main() {
printf("%d", N);
}- A. undefined (0)
- B. Compilation error: N is redefined
- C. 5
- D. 10
Correct answer: D. 10
#undef removes the previous definition of N entirely, so the subsequent #define N 10 is a fresh, unconflicting definition (not an illegal redefinition). By the time main is compiled, N expands to 10.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c int a = 10; int p = &a; int pp = &p; pp = 20; printf("%d %d %d", a, p, pp);
- Assume a 64-bit LP64 ABI. What is printed? c char names[] = {"Alice", "Bob", "Carol"}; char p = names; p++; printf("%s %s", p, (names + 2));
- Assume a 64-bit LP64 ABI. What is printed? c int a[5] = {10, 20, 30, 40, 50}; int p = a + 4; int q = a; printf("%ld %d %d", p - q, (p…
- Assume a 64-bit LP64 ABI. What is printed? c void modify(int arr[], int n) { for (int i = 0; i < n; i++) arr[i] += 100; } int main(void) {…
- Assume a 64-bit LP64 ABI. What is printed? c int nums[] = {1, 2, 3, 4, 5}; int p = nums; for (int i = 0; i < 5; i++) { printf("%d ", p); p…
- Assume a 64-bit LP64 ABI. What is printed? c int a = 5; int p = &a; void vp = p; int p2 = (int )vp; p2 = 99; printf("%d %d", a, p);