Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Structures and Pointers in C

Total questions: 35

Worksheet time: 22mins

Name
Class
Date
1.

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

a)

string

b)

struct

c)

char

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)

array

c)

Function

d)

None

4.

What is the output of this C code?

void main()

{

struct student

{

int no;

char name[20];

};

struct student s;

s.no = 8;

printf("%d", s.no);

}

a)

Nothing

b)

Compile error

c)

8

d)

Junk

5.

Memory allocated for structure members are always contigious

a)

True

b)

False

6.

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

7.

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

8.

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

9.

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

10.

Members of a union are accessed as_____________.

a)

union-name.member

b)

union-pointer->member

c)

Both a & b

d)

None of the mentioned

11.

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

12.

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

13.

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

14.

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

15.

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

16.

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

17.

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

18.

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

19.

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

20.

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

21.

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

22.

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

23.

The __________, also known as the address operator, returns the memory address of a variable.

a)

asterisk (* )

b)

ampersand ( & )

c)

percent sign ( % )

d)

exclamation point ( ! )

24.

In a C Program if

int a = 5;

Int *ptr = &a;

then the printf statement with

&a, a, *ptr , ptr

a)

adrress, Value, Value, Adress

b)

address, value, value, value

c)

all address

d)

All values

25.

In a C program,

int a = 20;

*ptr = &a;

**dptr = &ptr;

printf ("%d", **dptr);


prints

a)

address of a

b)

address of ptr

c)

value of a

d)

address of dptr

26.

What does this command do?.

a)

Creates a pointer of type integer that is initially pointing to null.

b)

Creates a pointer of type integer that is initially pointing to 0.

c)

Creates a pointer in the heap

d)

None of the answers are valid

27.

What will be output?

int i=10;

int *p;

p=&i;

i+=5;

printf("\n i=%d *p=%d", i,*p)

a)

i=10, *p=10

b)

i=10, *p=15

c)

i=15, *p=15

d)

i=15, *p=10

28.

Code to change the 3rd array value to 50 using pointers

int main(){

int a[] = {10,20,30};

int *p = a;

----------------------;

}

a)

p+3 = 50

b)

*(p+3) = 50

c)

*p+2 = 50

d)

*(p+2) = 50

29.

int main()

{

int arri[] = {1, 2 ,3};

int *ptri = arri;

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

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

return 0;

}

a)

3 3

b)

12 12

c)

12 4

d)

4 4

30.

What do the following declaration signify?


char *arr[10];

a)

arr is a array of 10 character pointers.

b)

arr is a array of function pointer.

c)

arr is a array of characters.

d)

arr is a pointer to array of characters.

31.

What is the output of C program with arrays and pointers.?

int main()

{

int size=4;

int a[size];

a[0]=5;

a[1]=6;

a[2]=7;

a[3]=8;

printf("%d %d", *(a+2), a[1]);

}

a)

8 6

b)

7 6

c)

6 6

d)

Compiler error

32.

Which of the following pointer is Wild

a)

int *p;

b)

int *q=&a;

c)

int *v=NULL;

d)

void *g;

33.

If 5 is added to the address value 'A' of an integer variable the new address is

a)

A +5

b)

A+ 10

c)

A+ 20

d)

Data insufficient

34.

Dynamic memory allocation occurs

a)

when a new variable is created by the compiler

b)

when a new variable is created at runtime

c)

when a pointer fails to dereference the right variable

d)

when a pointer is assigned an incorrect address

35.
What function should be used to free the memory allocated by calloc() ?
a)
dealloc();
b)
malloc(variable_name, 0)
c)
free();
d)
memalloc(variable_name, 0)