Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NETUncategorized

C Programming Questions and Answers – Arrays of Structures

C Programming Questions and Answers – Arrays of Structures

1.The correct syntax to access the member of the ith structure in the array of structures is?

Assuming: struct temp

{

int b;

}s[50];

a) s.b.[i];

b) s.[i].b;

c) s.b[i];

d) s[i].b;

View Answer

Answer:d 

2.Comment on the output of this C code?

#include <stdio.h>

struct temp

{

int a;

int b;

int c;

};

main()

{

struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

}

a) No Compile time error, generates an array of structure of size 3

b) No Compile time error, generates an array of structure of size 9

c) Compile time error, illegal declaration of a multidimensional array

d) Compile time error, illegal assignment to members of structure

View Answer

Answer:a 

3.Which of the following uses structure?

a) Array of structures

b) Linked Lists

c) Binary Tree

d) All of the mentioned

View Answer

Answer:d 

4.What is the correct syntax to declare a function foo() which receives an array of structure in function?

a) void foo(struct *var);

b) void foo(struct *var[]);

c) void foo(struct var);

d) None of the mentioned

View Answer

Answer:a

5.What is the output of this C code?

(Assuming size of int be 4)

#include <stdio.h>

struct temp

{

int a;

int b;

int c;

} p[] = {0};

main()

{

printf(“%d”, sizeof(p));

}

a) 4

b) 12

c) 16

d) Can’t be estimated due to ambigous initialization of array

View Answer

Answer:b 

6.What is the output of this C code?

#include <stdio.h>

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(“%s%s”, s[0].name, s[1].name);

}

a) alan alan alan turing

b) alan alan turing turing

c) alan turing alan turing

d) Run time error

View Answer

Answer:a 

7.What is the output of this C code?

#include <stdio.h>

struct student

{

char *name;

};

struct student s[2], r[2];

void main()

{

s[0].name = “alan”;

s[1] = s[0];

r = s;

printf(“%s%s”, r[0].name, r[1].name);

}

a) alan alan

b) Compile time error

c) Varies

d) Nothing

View Answer

Answer:b  

8.What is the output of this C code?

#include <stdio.h>

struct student

{

char *name;

};

void main()

{

struct student s[2], r[2];

s[1] = s[0] = “alan”;

printf(“%s%s”, s[0].name, s[1].name);

}

a) alan alan

b) Nothing

c) Compile time error

d) Varies

View Answer

Answer:c 

9.What is the output of this C code?

#include <stdio.h>

struct student

{

};

void main()

{

struct student s[2];

printf(“%d”, sizeof(s));

}

a) 2

b) 4

c) 8

d) 0

View Answer

Answer:d

10.What is the output of this C code?

#include <stdio.h>

struct point

{

int x;

int y;

};

void foo(struct point*);

int main()

{

struct point p1[]  =  {1, 2, 3, 4};

foo(p1);

}

void foo(struct point p[])

{

printf(“%d\n”, p[1].x);

}

a) Compile time error

b) 3

c) 2

d) 1

View Answer

Answer:b 

11.What is the output of this C code?

#include <stdio.h>

struct point

{

int x;

int y;

};

void foo(struct point*);

int main()

{

struct point p1[] = {1, 2, 3, 4};

foo(p1);

}

void foo(struct point p[])

{

printf(“%d\n”, p->x);

}

a) 1

b) 2

c) 3

d) Compile time error

View Answer

Answer:a 

12.What is the output of this C code?

#include <stdio.h>

struct point

{

int x;

int y;

};

void foo(struct point*);

int main()

{

struct point p1[] = {1, 2, 3, 4};

foo(p1);

}

void foo(struct point p[])

{

printf(“%d %d\n”, p->x, ++p->x);

}

a) 1 2

b) 2 2

c) Compile time error

d) Undefined behaviour

View Answer

Answer:b 

13.What is the output of this C code?

#include <stdio.h>

struct point

{

int x;

int y;

} p[] = {1, 2, 3, 4, 5};

void foo(struct point*);

int main()

{

foo(p);

}

void foo(struct point p[])

{

printf(“%d %d\n”, p->x, p[2].y);

}

a) 1 0

b) Compile time error

c) 1 somegarbagevalue

d) Undefined behaviour

View Answer

Answer:a  

14.What is the output of this C code?

#include <stdio.h>

struct point

{

int x;

int y;

};

void foo(struct point*);

int main()

{

struct point p1[] = {1, 2, 3, 4, 5};

foo(p1);

}

void foo(struct point p[])

{

printf(“%d %d\n”, p->x, p[3].y);

}

a) Compile time error

b) 1 0

c) 1 somegarbagevalue

d) None of the mentioned

View Answer

Answer:c

15.What is the output of this C code?

#include <stdio.h>

struct point

{

int x;

int y;

};

void foo(struct point*);

int main()

{

struct point p1[] = {1, 2, 3, 4, 5};

foo(p1);

}

void foo(struct point p[])

{

printf(“%d %d\n”, p->x, (p + 2).y);

}

a) Compile time error

b) 1 0

c) 1 somegarbagevalue

d) Undefined behaviour

View Answer

Answer:a  

16.What is the output of this C code?

#include <stdio.h>

struct point

{

int x;

int y;

};

void foo(struct point*);

int main()

{

struct point p1[] = {1, 2, 3, 4, 5};

foo(p1);

}

void foo(struct point p[])

{

printf(“%d %d\n”, p->x, (p + 2)->y);

}

a) Compile time error

b) 1 0

c) 1 somegarbagevalue

d) undefined behaviour

View Answer

Answer:b 

17.What is the output of this C code?

#include <stdio.h>

struct student

{

char *c;

};

void main()

{

struct student s[2];

printf(“%d”, sizeof(s));

}

a) 2

b) 4

c) 16

d) 8

View Answer

Answer:d 

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button