wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Structure C

Total questions: 60

Worksheet time: 40mins

Name
Class
Date
1.

Which of the following are themselves a collection of different data types?

a)

string

b)

char

c)

struct

d)

all

2.

Which operator connects the structure name to its member name?

a)

-

b)

.

c)

=

d)

>>

3.

Which of the following cannot be a structure member?

a)

another structure

b)

Function

c)

array

d)

None

4.

Which of the following structure declaration will throw an error?

a)


struct temp{ } s;

main(){}

b)


struct temp{ };

struct temp s;

main(){ }

c)

struct temp s;

struct temp{ };

main(){ }

d)

None

5.

What is the output of this C code?

a)

Nothing

b)

Compile error

c)

8.0

d)

8

6.

Size of a union is determined by size of the.

a)

First member in the union

b)

Last member in the union

c)

Biggest member in the union

d)

Sum of the sizes of all members

7.

Assuming size of long int is 4 bytes, what will be the output for:

typedef long long int L = 24;

printf("Size of long long int is :");

printf("%d",sizeof(L));

a)

24

b)

4

c)

8

d)

Error

8.

What will be the output ?

a)

Name:

Subject:

Percentage: 86.50000

b)

Name:Raju

Subject:

Percentage: 86.50000

c)

Name: Raju

Subject: Maths

Percentage: 86.50000

d)

Error

9.

Memory allocated for structure members are always contigious ?

a)

True

b)

False

10.

What do you understand by:

void update(struct student *s);

a)


update is a function that takes an argument as pointer to structure variable and returns nothing

b)

update is a method that takes structure type variable as parameter

c)


Error, we cannot pass structure variable as pointer to a function

d)

update takes pointer argument but it cannot return void

11.

Which keyword is used to declare structure variable?

a)

Structure

b)

struct

c)

s

d)

sruct s

12.

Structure is a variable which holds____________________

a)

Different data types

b)

similar data types

c)

only int and float

d)

only int and char

13.

which of the following structure definition is correct one?

a)

struct stu

{

----}s

b)

struct stu

{

----}s;

c)

struct stu

{

----};

d)

both b and c

14.

How to access data member of a structure?

a)

s->rollno

b)

s.rollno

c)

rollno

d)

None of the above

15.

Is it necessary to create a structure variable to access its members? True or False

a)

True

b)

False

16.

What is array of structure?

a)

Single structure

b)

Collection of structure

c)

Different structure

d)

Collection of data types

17.

Is it possible to assign values of data members with the structure variable?

a)

True

b)

False

18.

Below code is, Pointer structure variable declaration and Initialization. Which is correct?

a)

struct *p=&s;

b)

struct stud *p=&s;

c)

struct stud p=&s;

d)

struct stud *p=s;

19.

Which operator is used to access data member of a structure using pointer variable?

a)

arrow

b)

->

c)

dot operator

d)

both a and b

20.

Pointer variable to a structure holds address of ___________

a)

part of a structure

b)

structure

c)

datamember

d)

values

21.

Which of the following are themselves a collection of different data types?

a)

string

b)

structures

c)

char

d)

all of the mentioned

22.

User-defined data type can be derived by___________

a)

struct

b)

enum

c)

typedef

d)

all of the mentioned

23.

What will be the output of the following C code?

#include <stdio.h>

struct student

{

int no;

char name[20];

}

void main()

{

struct student s;

s.no = 8;

printf("hello");

}

a)

Compile time error

b)

Nothing

c)

hello

d)

Varies

24.

Which of the following return-type cannot be used for a function in C?

a)

char *

b)

struct

c)

void

d)

none of the mentioned

25.

Which of the following is not possible under any scenario?

a)

s1 = &s2;

b)

s1 = s2;

c)

(*s1).number = 10;

d)

None of the mentioned

26.

Which of the following operation is illegal in structures?

a)

Typecasting of structure

b)

Pointer to a variable of the same structure

c)

Dynamic allocation of memory for structure

d)

All of the mentioned

27.

Comment on the output of the following 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

28.

Which of the following uses structure?

a)

Array of structures

b)

Linked Lists

c)

Binary Tree

d)

All of the mentioned

29.

What will be the output of the following C code?


#include <stdio.h>

struct student

{

char *c;

};


void main()

{

struct student m;

struct student *s = &m;

s->c = "hello";

printf("%s", m.c);

}

a)

Run time error

b)

Nothing

c)

hello

d)

Varies

30.

Which of the following is not possible regarding the structure variable?

a)

A structure variable pointing to itself

b)

A structure variable pointing to another structure variable of same type

c)

2 different type of structure variable pointing at each other

d)

None of the mentioned

31.

Which of the following will stop the loop at the last node of a linked list in the following C code snippet?


struct node

{

struct node *next;

};

a)

while (p != NULL)

{

p = p->next;

}

b)

while (p->next != NULL)

{

p = p->next;

}

c)

while (1)

{

p = p->next;

if (p == NULL)

break;

}

d)

All of the mentioned

32.

What will be the output of the following C code?

#include <stdio.h>

struct student

{

char a[5];

};

void main()

{

struct student s[] = {"hi", "hey"};

printf("%c", s[0].a[1]);

}

a)

h

b)

i

c)

e

d)

y

33.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

char *a[3] = {"hello", "this"};

printf("%s", a[1]);

}

a)

hello

b)

Varies

c)

this

d)

Compile time error

34.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

int lookup[100] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

printf("%d", lookup[3]);

}

a)

2

b)

4

c)

Compile time error

d)

3

35.

Which algorithm is used for searching in the table?

a)

List search

b)

Informed search

c)

Hash search

d)

Adversarial search

36.

What will be the output of the following C code?

#include <stdio.h>

union stu

{

int ival;

float fval;

};

void main()

{

union stu r;

r.ival = 5;

printf("%d", r.ival);

}

a)

9

b)

Compile time error

c)

16

d)

5

37.

A union cannot be nested in a structure

a)

True

b)

False

38.

size of union is size of the longest element in the union

a)

Yes

b)

No

39.

Which of the following share a similarity in syntax?

1. Union,

2. Structure,

3. Arrays and

4. Pointers

a)

3 and 4

b)

1 and 2

c)

1 and 3

d)

1, 3 and 4

40.

What is the correct syntax to initialize bit-fields in an structure?

a)

struct temp

{

unsigned int a : 1;

}s;

b)

struct temp

{

unsigned int a = 1;

}s;

c)

struct temp

{

unsigned float a : 1;

}s;

d)

None of the mentioned

41.

Which of the following operation is illegal in structures?

a)

Typecasting of structure

b)

Pointer to a variable of same structure

c)

Dynamic allocation of memory for structure

d)

All of the mentioned

42.

What is the size of a C structure?

a)

C structure is always 128 bytes

b)

Size of C structure is the total bytes of all elements of structure

c)

Size of C structure is the size of largest element

d)

None of the above

43.

Which operator connects the structure name to its member name?

a)

-

b)

.

c)

/

d)

\

44.

Which of the following cannot be a structure member?

a)

Another structure

b)

Array

c)

Function

d)

None of the mentioned

45.

Number of bytes in memory taken by the below structure is?

struct test

{

int k;

char c;

};

a)

Multiple of integer size

b)

integer size+character size

c)

Depends on the platform

d)

Multiple of word size

46.

Size of a union is determined by size of the

a)

Biggest member in the union

b)

First member in the union

c)

Last member in the union

d)

Sum of the sizes of all members

47.

A C structure or User defined datatype is also called ________.

a)

Derived data type

b)

Secondary data type

c)

Aggregate data type

d)

All the above

48.

Members of a union are accessed as_____________.

a)

union-name.member

b)

union-pointer->member

c)

Both a & b

d)

None of the mentioned

49.

Choose a correct statement about C structures

a)

Structure elements can be initialized at the time of declaration

b)

Structure members can not be initialized at the time of declaration

c)

Only integer members of structure can be initialized at the time of declaraion

d)

None of the above

50.

What is the output of C program?

#include <stdio.h>

int main()

{

structure hotel

{

int items;

char name[10];

}a;

strcpy(a.name, "TAJ");

a.items=10;

printf("%s", a.name);

return 0;

}

a)

TAJ

b)

Empty string

c)

Compiler error

d)

None of the above

51.

What is the output of C program?

#include <stdio.h>

int main()

{

struct book

{

int pages;

char name[10];

}a;

a.pages=10;

strcpy(a.name,"Cbasics");

printf("%s=%d", a.name,a.pages);

return 0;

}

a)

empty string=10

b)

Cbasics=10

c)

C=basics

d)

Compiler error

52.

What is the output of C program?

#include <stdio.h>

int main()

{

struct ship

{

int size;

char color[10];

}boat1, boat2;

boat1.size=10;

boat2 = boat1;

printf("boat2=%d",boat2.size);

return 0;

}

a)

boat2=10

b)

boat2=-1

c)

boat2=0

d)

Compiler error

53.

What is the output of C program with structures?

#include <stdio.h>

int main()

{

struct ship

{

char color[10];

}boat1, boat2;

strcpy(boat1.color,"RED");

printf("%s ",boat1.color);

boat2 = boat1;

strcpy(boat2.color,"YELLOW");

printf("%s",boat1.color);

return 0;

}

a)

RED RED

b)

RED YELLOW

c)

YELLOW YELLOW

d)

Compiler error

54.

What is the output of c program with structures?

#include <stdio.h>

int main()

{

struct tree

{

int h;

int w;

};

struct tree tree1={10};

printf("%d ",tree1.w);

printf("%d",tree1.h);

return 0;

}

a)

0 0

b)

10 0

c)

0 10

d)

10 10

55.

What is the output of C program?

#include <stdio.h>

int main()

{

struct laptop

{

int cost;

char brand[10];

};

struct laptop L1={5000,"ACER"};

struct laptop L2={6000,"IBM"};

printf("Name=%s",L1.brand);

return 0;

}

a)

Name=ACER

b)

Name=

c)

Compiler error

d)

None of the above

56.

What is the output of C program with Structure pointer in C?

#include <stdio.h>

int main()

{

struct books{

int pages;

char str[4];

}*ptr;

printf("%d",sizeof(ptr));

return 0;

}

a)

2

b)

6

c)

7

d)

4

57.

What is the output of C program with structures pointers?

#include <stdio.h>

int main()

{

struct forest

{

int trees;

int animals;

}F1,*F2;

F1.trees=1000;

F1.animals=20;

F2=&F1;

printf("%d ",F2.animals);

return 0;

}

a)

0

b)

20

c)

Compiler error

d)

None of the above

58.

What is the output of this C program?

int main()

{

struct bus

{

int seats;

}F1, *F2;

F1.seats=20;

F2=&F1;

F2->seats=15;

printf("%d ",F1.seats);

return 0;

}

a)

15

b)

20

c)

0

d)

Compiler Error

59.

What is the output of C program with structure array pointers?

#include <stdio.h>

int main()

{

struct car

{

int km;

}*p1[2];

struct car c1={1234};

p1[0]=&c1;

printf("%d ",p1[0]->km);

return 0;

}

a)

0

b)

1

c)

1234

d)

Compiler error

60.

What is a structure in C language?

a)

A structure is a collection of elements that can be of same data type

b)

A structure is a collection of elements that can be of different data type

c)

Elements of a structure are called members

d)

All the above