ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int f(void) {
static int a[3];
a[0]++;
return a[0];
}
int main(void) {
int x = f();
int y = f();
int z = f();
printf("%d %d %d", x, y, z);
}- A. 3 3 3
- B. 1 2 3
- C. 1 1 1
- D. 0 1 2
Correct answer: B. 1 2 3
The static array is zero-initialised once and a[0] increments on each call, so the three calls return 1, 2 and 3.
More C Programming questions
- What is printed? Assume short is 2 bytes with 2-byte alignment and char is 1 byte. c #include <stdio.h> struct S { short a; char b; }; int…
- What is printed? Assume uint8t is 8 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint8t a = 5, b = 10; uint8t d = a…
- Seven people stand in a circle and every third person is removed until one is left. The recursion J(n, k) gives the 1-based survivor…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 2, 3, 4, 5, 6}, best = 0; for (int i = 0; i + 3 <= 6; i++) { int s =…
- What is printed? c #include <stdio.h> int main(void) { printf("%d", (-17 / 5) 5 + (-17 % 5) == -17); }
- How many leading zero bits does the 16-bit value 0x0123 have? Count them with this program. c #include <stdint.h> #include <stdio.h> int…