ProgrammingHardProduct company OA
What is printed?
What is printed?
printf("%d %d %d", atoi("42abc"), atoi(" -7x"), atoi("x9"));- A. 42 -7 9
- B. 42 0 0
- C. 0 -7 0
- D. 42 -7 0
Correct answer: D. 42 -7 0
atoi skips leading white space, reads an optional sign and then as many digits as it can, stopping at the first non-digit. "42abc" gives 42, " -7x" gives -7, and "x9" has no leading digits at all, so it gives 0; atoi does not hunt for digits later in the string.
More C Programming questions
- What is printed? c int a = 0, b = 0; int n = sscanf("12 abc 7", "%d %d", &a, &b); printf("%d %d %d", n, a, b);
- 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);