ProgrammingHardTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
#include <string.h>
int main(void) {
char s[] = "hi\0there";
printf("%zu %zu", sizeof s, strlen(s));
}- A. 8 2
- B. 9 8
- C. 10 2
- D. 9 2
Correct answer: D. 9 2
The array holds 8 characters plus the terminating null, so sizeof s is 9. strlen stops at the first embedded null, giving 2.
More C Programming questions
- What is printed? c #include <stdio.h> int A(int m, int n) { if (m == 0) return n + 1; if (n == 0) return A(m - 1, 1); return A(m - 1, A(m…
- What is printed? c #include <stdio.h> unsigned long long g(unsigned n, unsigned long long acc) { return n == 0 ? acc : g(n - 1, acc 3 +…
- What is printed? c #include <stdio.h> long long memo[50]; int calls = 0; long long f(int n) { calls++; if (n < 2) return 1; if (memo[n])…
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { int x = (const int )a, y = (const int )b…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint16t x = 0xABCD; x = (uint16t)((x << 4) | (x >> 12))…
- Assume unsigned int is 32 bits. What is printed? c #include <stdio.h> int main(void) { unsigned n = 0x1FFFF, p = 1; while (p 2 <= n) p =…