ProgrammingModerateWipro · Capgemini
A function in a.c is declared `static int helper(void) { ... }`. Which statement is true?
- A. It is placed in read-only memory and cannot be called through a pointer
- B. Its local variables keep their values between calls
- C. It can be called from any file that declares extern int helper(void);
- D. It can be called only from code in a.c; another file can define its own helper without a clash
Correct answer: D. It can be called only from code in a.c; another file can define its own helper without a clash
On a function, static means internal linkage: the name is private to its translation unit. It says nothing about the function's locals (only static locals persist). Code in a.c can still pass a pointer to it elsewhere; other files just cannot name it.
More C Programming questions
- What is printed? c #define MAX(a, b) a > b ? a : b int x = 3, y = 7; printf("%d", 2 MAX(x, y));
- Assume IEEE-754 single-precision float with float arithmetic done in float. Which loops terminate? c int c1 = 0, c2 = 0; for (float f = 0…
- What is printed? c struct Shape { int w, h; int (area)(struct Shape ); }; int rect(struct Shape s) { return s->w s->h; } int tri(struct…
- What is printed? c int i = 0, s = 0; top: s += i; if (++i < 5) goto top; printf("%d %d", s, i);
- What is printed? c int calls = 0; int mx(int a, int lo, int hi) { calls++; if (lo == hi) return a[lo]; int m = (lo + hi) / 2; int l =…
- What is printed? c int a[] = {1, 2, 3}, p = a; int x = ++p++; int y = p++ 10; printf("%d %d %d %d", x, y, a[0], p);