GATE CSE C Programming Practice Test – Structures & Unions | Set 1

Questions 91-95 of 100

Your score 0/100 0 answered
Correct 0 Incorrect 0 Unanswered 100 Accuracy 0%

Question 91

NAT · Numerical Answer 1 mark

What is the total size in bytes of the structure on a 32-bit machine (int=4B, short=2B, 4B alignment enforced)?

CODE
struct Data {
    short s;
    int i;
    short t;
};
Answers for question 91

Question 92

NAT · Numerical Answer 1 mark

What will be printed by the following code?

C
#include <stdio.h>
union U {
    int x;
    char c[4];
};
int main(void) {
    union U u;
    u.x = 0;
    u.c[0] = 5;
    u.c[1] = 2;
    printf("%d", u.c[0] + u.c[1]);
    return 0;
}
Answers for question 92

Question 93

NAT · Numerical Answer 2 mark

How many total bytes are allocated on the stack for the array declaration 'struct Node arr[5];' if sizeof(struct Node) is 16 bytes?

Answers for question 93

Question 94

NAT · Numerical Answer 1 mark

What is the output of the C program?

C
#include <stdio.h>
struct Box {
    int h, w, l;
};
int volume(struct Box b) {
    return b.h * b.w * b.l;
}
int main(void) {
    struct Box b = {2, 3, 4};
    printf("%d", volume(b));
    return 0;
}
Answers for question 94

Question 95

NAT · Numerical Answer 2 mark

What is the printed value of total?

C
#include <stdio.h>
struct Num {
    int val;
};
int main(void) {
    struct Num a = {10}, b = {20}, c = {30};
    struct Num arr[3] = {a, b, c};
    int total = 0;
    for(int i=0; i<3; i++) total += arr[i].val;
    printf("%d", total);
    return 0;
}
Answers for question 95
Scroll to Top