wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

SESSIONAL EXAM(Programmin Lab)

Total questions: 15

Worksheet time: 14mins

Name
Class
Date
1.

Which of the following function is used to allocate memory and initialize it to zero?

a)
malloc
b)
realloc
c)
free
d)
calloc
2.

What is the correct syntax to dynamically allocate memory for an array of 10 integers?

a)
int array = malloc(10 * sizeof(int));
b)
int *array = new int[10];
c)
int array[10];
d)
int *array = (int *)malloc(10 * sizeof(int));
3.

What is the size of a structure containing an int and a char (assuming 4-byte int and 1-byte char on a 4-byte aligned machine)?

a)
5 bytes
b)
8 bytes
c)
6 bytes
d)
7 bytes
4.

union data {

int i;

float f;

};

union data d;

d.i = 10;

d.f = 3.14;

printf("%d", d.i);

a)
The output will be 10.
b)
The output will be 3.14.
c)
The output is unpredictable, often a garbage value.
d)
The output will be 0.
5.

int fun(int n) {

if (n == 0) return 0;

else return n + fun(n - 1);

}

int main(){

printf("%d", fun(3));

return 0;

}

a)
9
b)
7
c)
5
d)
6
6.

void print(int n) {

if (n == 0) return;

print(n - 1);

printf("%d ", n);

}

int main(){

print(3);

return 0;

}

a)
3 2 1
b)
1 2 3
c)
2 1 0
d)
0 1 2
7.

int a = 5, b = 10;

int p = &a, q = &b;

*p = *q;

printf("%d %d", a, b);

a)
5 5
b)
10 5
c)
10 10
d)
5 10
8.

void fun(int *p) {

p = p + 10;

}

int main() {

int x = 5;

fun(&x);

printf("%d", x);

}

a)

5

b)
10
c)

15

d)

garbage

9.

What will be the size of the array declared as char name[] = "C Programming";?

a)
12
b)
16
c)
14
d)
15
10.

void test(int a) {

a = a + 5;

}

int main() {

int x = 10;

test(x);

printf("%d", x);

}

a)
10
b)
5
c)
15
d)
20
11.

int main(){

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

printf("%d", arr[2]);

return 0;

}

a)
2
b)
1
c)

garbage value

d)
0
12.

int arr[] = {1, 2, 3, 4};

printf("%lu", sizeof(arr));

a)

4

b)

16

c)
5
d)

3

13.

int main(){

int i = 0;

while(i++ < 3){

printf("%d ", i);

}

return 0;

}

a)
1 2 3
b)
2 3 4
c)
1 2 4
d)
0 1 2
14.

int main(){

int x = 0;

if (x)

printf("True");

else

printf("False");

return 0;

}

a)
True
b)
False
c)
Undefined
d)
Error
15.

What is the result of the expression ++a - b++ when a = 5 and b = 3?

a)
2
b)
4
c)
6
d)
3