wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C Language Test 3

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

In which of the following languages is function overloading not possible?

a)

C

b)

C++

c)

Java

d)

Python

2.

Which of the following function is used to open a file in C++?

a)

fopen

b)

fclose

c)

fseek

d)

fgets

3.

Which of the following are correct file opening modes in C?

a)

r

b)

rb

c)

w

d)

All of the above.

4.

What is the return type of the fopen() function in C?

a)

Pointer to a FILE object.

b)

Pointer to an integer.

c)

An integer.

d)

An integer.

5.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    int ch = 2;

    switch(ch) {

        case 1: printf("1 ");

        case 2: printf("2 ");

        case 3: printf("3 ");

        default: printf("None");

    }

}

int main() {

    solve();

        return 0;

}

a)

1 2 3 None

b)

2

c)

2 3 None

d)

None

6.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    int x = 1, y = 2;

    printf(x > y ? "Greater" : x == y ? "Equal" : "Lesser");

}

int main() {

    solve();

        return 0;

}

a)

Greater

b)

Lesser

c)

Equal

d)

None of the above.

7.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    int n = 24;

    int l = 0, r = 100, ans = n;

    while(l <= r) {

        int mid = (l + r) / 2;

        if(mid * mid <= n) {

            ans = mid;

            l = mid + 1;

        }

        else {

            r = mid - 1;

        }

    }

    printf("%d", ans);

}

int main() {

    solve();

        return 0;

}

a)

5

b)

4

c)

3

d)

6

8.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    printf("%d ", 9 / 2);

    printf("%f", 9.0 / 2);

}

int main() {

    solve();

        return 0;

}

a)

4 4.5000

b)

4 4.000

c)

4.5000 4.5000

d)

4 4

9.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    int x = 2;

    printf("%d", (x << 1) + (x >> 1));

}

int main() {

    solve();

        return 0;

}

a)

5

b)

4

c)

2

d)

1

10.

What will be the output of the following code snippet?

#include <stdio.h>

#define VAL 5

int getInput() {

    return VAL;

}

void solve() {

    const int x = getInput();

    printf("%d", x);

}

int main() {

    solve();

        return 0;

}

a)

5

b)

Garbage Value

c)

Compilation Error

d)

0

11.

How to find the length of an array in C?

a)

sizeof(a)

b)

sizeof(a[0])

c)

sizeof(a) / sizeof(a[0])

d)

sizeof(a) * sizeof(a[0])

12.

Which of the following is not a storage class specifier in C?

a)

volatile

b)

extern

c)

typedef

d)

static

13.

What will be the output of the following code snippet?

#include <stdio.h>

void solve(int x) {

    if(x == 0) {

        printf("%d ", x);

        return;

    }

    printf("%d ", x);

    solve(x - 1);

    printf("%d ", x);

}

int main() {

    solve(3);

        return 0;

}

a)

3 2 1 0 1 2 3

b)

3 2 1 0

c)

0 1 2 3

d)

None of the above

14.

What will be the output of the following code snippet?

#include <stdio.h>

int search(int l, int r, int target, int a[]) {

    int mid = (l + r) / 2;

    if(a[mid] == target) {

        return mid;

    }

    else if(a[mid] < target) {

        return search(mid + 1, r, target, a);

    }

    else {

        return search(0, mid - 1, target, a);

    }

}

void solve() {

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

    printf("%d", search(0, 5, 3, a));

}

int main() {

    solve();

        return 0;

}

a)

2

b)

3

c)

4

d)

5

15.

What will be the output of the following code snippet?

#include <stdio.h>

int get(int n) {

    if(n <= 1) {

        return n;

    }

    return get(n - 1) + get(n - 2);

}

void solve() {

    int ans = get(6);

    printf("%d", ans);

}

int main() {

    solve();

        return 0;

}

a)

5

b)

1

c)

0

d)

8

16.

What is the output of the following code snippet?

#include <stdio.h>

#include<stdlib.h>

void set(int *to) {

    to = (int*)malloc(5 * sizeof(int));

}

void solve() {

    int *ptr;

    set(ptr);

    *ptr = 10;

    printf("%d", *ptr);

}

int main() {

    solve();

        return 0;

}

a)

10

b)

Garbage Value

c)

Cannot Say

d)

The program may crash.

17.

Which of the following will occur if we call the free() function on a NULL pointer?

a)

Compilation Error.

b)

Runtime Error.

c)

Undefined Behaviour.

d)

The program will execute normally.

18.

Which of the following should be used to free memory from a pointer allocated using the “new” operator?

a)

free()

b)

delete

c)

realloc()

d)

None of the above.

19.

Which data structure is used to handle recursion in C?

a)

Stack.

b)

Queue.

c)

Deque.

d)

Trees.

20.

What will be the output of the following code snippet?

#include <stdio.h>

#define CUBE(x) x x x

void solve() {

    int ans = 216 / CUBE(3);

    printf("%d", ans);

}

int main() {

    solve();

        return 0;

}

a)

8

b)

648

c)

72

d)

None of the above.

21.

What will be the output of the following code snippet?

#include <stdio.h>

struct School {

    int age, rollNo;

};

void solve() {

    struct School sc;

    sc.age = 19;

    sc.rollNo = 82;

    printf("%d %d", sc.age, sc.rollNo);

}

int main() {

    solve();

        return 0;

}

a)

19 82

b)

Compilation Error

c)

82 19

d)

None of the above.

22.

Which of the following is not true about structs in C?

a)

No Data Hiding.

b)

Functions are allowed inside structs.

c)

Constructors are not allowed inside structs.

d)

Cannot have static members in the struct body.

23.

What will be the output of the following code snippet?

#include <stdio.h>

struct School {

    int age, rollNo;

};

void solve() {

    struct School sc;

    sc.age = 19;

    sc.rollNo = 82;

    printf("%d", (int)sizeof(sc));

}

int main() {

    solve();

        return 0;

}

a)

1

b)

4

c)

8

d)

16

24.

What will be the output of the following code snippet?

#include <stdio.h>

union School {

    int age, rollNo;

    double marks;

};

void solve() {

    union School sc;

    sc.age = 19;

    sc.rollNo = 82;

    sc.marks = 19.04;

    printf("%d", (int)sizeof(sc));

}

int main() {

    solve();

        return 0;

}

a)

4

b)

8

c)

16

d)

12

25.

What will be the output of the following code snippet?

#include <stdio.h>

#include<string.h>

void solve() {

    char s[] = "Hello";

    printf("%s ", s);

    char t[40];

    strcpy(t, s);

    printf("%s", t);

}

int main() {

    solve();

        return 0;

}

a)

Hello Hello

b)

Hello

c)

Compilation Error

d)

None of the above.