ProgrammingHardProduct company OA · GATE CS
What is printed?
What is printed?
struct P { int x; int y; } p = {7, 9};
int *q = (int *)&p;
printf("%d", *q);- A. Undefined behaviour: the cast is not allowed
- B. 7
- C. 9
- D. An address
Correct answer: B. 7
The standard guarantees there is no padding before the first member, and that a pointer to a struct, suitably converted, points to its first member. So q points at p.x and prints 7.
More C Programming questions
- What is printed? c int p(int n, int m) { / ways to write n as a sum of parts <= m / if (n == 0) return 1; if (n < 0 || m == 0) return 0…
- What is printed? c printf("%#x %#o %x", 255, 8, -1 & 0xFF);
- Assume 8-bit unsigned char. What is printed? c printf("%d %d %d", (int)-3.7, (unsigned char)-1, (int)(0.1 30));
- What is printed? c int ways(int amt, int k) { static const int c[] = {1, 2, 5}; if (amt == 0) return 1; if (amt < 0 || k == 0) return 0…
- On an LP64 system (8-byte pointers, 4-byte int), what is printed? c int a[10]; printf("%zu %zu %zu", sizeof(&a), sizeof(&a), sizeof(a + 0));
- What is printed? c int i = 0, j = 0; if (i++ & j++) ; if (i++ && j++) ; printf("%d %d", i, j);