ProgrammingModerateProduct company OA
A header config.h is wrapped as `#ifndef CONFIG_H` / `#define CONFIG_H` / … / `#endif`. What problem does this prevent?
- A. Macros from the header becoming visible in other source files
- B. The header's contents being processed twice in one translation unit, which would redefine its types
- C. The header's functions being compiled into every object file
- D. The header being linked into the program twice
Correct answer: B. The header's contents being processed twice in one translation unit, which would redefine its types
An include guard works per translation unit: the second time the same .c file pulls in config.h (often indirectly), CONFIG_H is already defined and the body is skipped, avoiding duplicate struct and typedef definitions. Linking and other source files are unaffected.
More C Programming questions
- With 4-byte int, after these lines run, which block can no longer be freed because no pointer to it remains? c int a = malloc(10…
- What is printed? c int pal(const char s, int i, int j) { if (i >= j) return 1; if (s[i] != s[j]) return 0; return pal(s, i + 1, j - 1); }…
- With 4-byte int, what is printed? c typedef int Row[3]; Row m[2] = {{1, 2, 3}, {4, 5, 6}}; Row p = m; printf("%zu %d", sizeof(Row)…
- What is printed? c int a = 0, b = 0, c = 0; if ((a = 2) && (b = 0) || (c = 3)) a++; printf("%d %d %d", a, b, c);
- Which line has undefined behaviour? c char a[] = "hi"; char p = "hi"; a[0] = 'H'; / (i) / p[0] = 'H'; / (ii) / char q = a; q[1] = 'I'; /…
- What is printed? c int calls = 0; int C(int n, int k) { calls++; return (k == 0 || k == n) ? 1 : C(n - 1, k - 1) + C(n - 1, k); } int…