ProgrammingVery hardGATE CS · Campus placements
int next(void) { static int c = 0; return ++c; } Each of three calls returns its value, and the three returns are added together. What is the total?
- A. 6
- B. 3
- C. 4
- D. 9
Correct answer: A. 6
The static counter keeps its value between calls, so the returns are 1, 2 and 3, summing to 6. An auto counter would return 1 every time and sum to 3.
More C Programming questions
- char s[] = "a0b"; What is strlen(s)?
- uint32t v = 0; for each digit d of the decimal string "4294967296", v = v 10 + d; What is v at the end?
- Using fib-like recursion where a stair can be climbed by 1 or 2 steps, the number of ways for 10 stairs is the recursion W(n) = W(n-1) +…
- What is sizeof "hi" in C?
- For unsigned a and b greater than 0 stored in uint32t, which test correctly detects that a b overflows?
- char words[] holds strings and must be sorted by length first and then alphabetically using qsort. Which comparator is correct?