ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int a = 0, b = 0;
int n = sscanf("12 abc 7", "%d %d", &a, &b);
printf("%d %d %d", n, a, b);- A. 1 12 7
- B. 1 12 0
- C. 2 12 0
- D. 2 12 7
Correct answer: B. 1 12 0
sscanf returns how many items it converted and stores. %d reads 12; the second %d meets "abc", fails, and scanning stops there, so the 7 is never reached and b keeps its 0. The return value 1 is how real code detects such bad input.
More C Programming questions
- With 4-byte int, what is printed? c int p = (int[]){10, 20, 30}; p[1] += 5; printf("%d %zu", p[1] + p[2], sizeof((int[]){10, 20, 30}) /…
- What is printed? c #define COUNT(...) (sizeof((int[]){VAARGS}) / sizeof(int)) printf("%zu %zu", COUNT(1, 2, 3), COUNT(7));
- After the call below, what is c? c int c = 0; void perm(char s, int k, int n) { if (k == n) { c++; return; } for (int i = k; i < n; i++) {…
- What is printed? c int steps = 0; int gcd(int a, int b) { steps++; return b == 0 ? a : gcd(b, a % b); } int main(void) { int g = gcd(1071…
- What is printed? c unsigned v = 0; const char b = "10110"; while (b) v = (v << 1) | (b++ - '0'); printf("%u", v);
- With 4-byte int, what is printed? c int a[2][3][4]; printf("%zu %zu %td", sizeof a[1], sizeof a[1][2], (char )&a[1][2][3] - (char )a);