wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Problem Solving and C Programming-Assignment 5

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which keyword is used to define a structure in C?

a)

struct

b)

record

c)

data

d)

union

2.

Which of the following correctly declares a structure?

a)

struct student { int roll; char name; };

b)

struct student ( int roll, char name );

c)

student struct { int roll; char name; };

d)

struct { int roll; char name; } student;

3.

How do you access a structure member using a structure variable s?

a)

s->name

b)

s.name

c)

s:name

d)

$#name

4.

In a union, the size of the union is equal to:

a)

Sum of all members

b)

Size of the smallest member

c)

Size of the largest member

d)

Always 4 bytes

5.

Which keyword is used to define a union?

a)

struct

b)

union

c)

type

d)

obj

6.

Which function is used to allocate memory dynamically?

a)

malloc()

b)

scanf()

c)

sizeof()

d)

printf()

7.

malloc() returns:

a)

a pointer to the allocated memory

b)

the size of the allocated memory

c)

an integer value

d)

a boolean value

8.

Which function is used to free dynamically allocated memory?

a)

delete()

b)

free()

c)

remove()

d)

dispose()

9.

What is the correct way to allocate memory for 10 integers?

a)

int *p = malloc(10);

b)

int *p = malloc(10 * sizeof(int));

c)

int p = malloc(sizeof(int));

d)

int *p = malloc(int);

10.

What is the correct way to access a structure member using a pointer ptr?

a)

ptr.name

b)

*&ptr.name

c)

ptr->name

d)

*ptr.name