ProgrammingHardTCS NQT · Infosys
Assume a pointer is 8 bytes and int is 4 bytes. What is printed?
Assume a pointer is 8 bytes and int is 4 bytes. What is printed?
#include <stdio.h>
void f(int v[]) {
printf("%zu ", sizeof v);
}
int main(void) {
int a[7];
printf("%zu ", sizeof a / sizeof a[0]);
f(a);
}- A. 7 28
- B. 28 8
- C. 7 8
- D. 7 4
Correct answer: C. 7 8
Inside main, sizeof a / sizeof a[0] counts the 7 elements. The parameter int v[] is really an int *, so sizeof v is the pointer size of 8.
More C Programming questions
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { char s[] = "hi0there"; printf("%zu %zu", sizeof s, strlen(s)); }
- 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))…