Programming for Problem Solving (3110003) MCQs

MCQs of Structure

Showing 11 to 17 out of 17 Questions
11.
Which of the following accesses a variable in structure b?
(a) b->var;
(b) b.var;
(c) b-var;
(d) b>var;
Answer:

Option (b)

12.
Which of the following accesses a variable in structure *b?
(a) b->var;
(b) b.var;
(c) b-var;
(d) b>var;
Answer:

Option (a)

13.
What is the output?

struct pens
{
    int color;
}p1[2];
void main()
{
    struct pens p2[3];
    p1[0].color=5;
    p1[1].color=9;
    printf("%d, ",p1[0].color);
    printf("%d",p1[1].color);
}

(a) 5, 5
(b) 5, 9
(c) 9, 5
(d) Compiler error
Answer:

Option (b)

14.
What is the output?

struct student
{
    char *name;
};
struct student s[2];
void main()
{
    s[0].name = "alan";
    s[1] = s[0];
    printf("%s %s", s[0].name, s[1].name);
    s[1].name = "turing";
    printf("\n%s %s", s[0].name, s[1].name);
}

(a) alan alan
alan turing
(b) alan alan
turing turing
(c) alan turing
alan turing
(d) None of these
Answer:

Option (a)

15.
What is the output?

struct point
{
    int x;
    int y;
} p[] = {1, 2, 3, 4};
int main()
{
   printf("%d %d\n", p[0].x, p[1].y);
   printf("%d %d\n", p[2].x, p[3].y);
}

(a) 1 2
3 4
(b) 1 0
2 0
(c) Compiler Error
(d) Blank
Answer:

Option (a)

16.
The correct syntax to access the member of the ith structure in the array of structures is?
struct temp
{
 int b;
}s[50];
(a) s.b.[i];
(b) s.[i].b;
(c) s.b[i];
(d) s[i].b;
Answer:

Option (d)

17.
What is the output?

void main()
{
    struct book
    {
        int pages;
    };
    struct book b,*ptr;
    b.pages = 100;
    ptr = &b;
    printf("%d ", b.pages);
    printf("\n%d ", ptr->pages);
}

(a) Compiler error
(b) 100
100
(c) 100
Blank
(d) 100
Address of b
Answer:

Option (b)

Showing 11 to 17 out of 17 Questions