wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C Language Test - 2

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What is the range of values that can be stored by int datatype in C?

a)

-(2^31) to (2^31) - 1

b)

-256 to 255

c)

-(2^63) to (2^63) - 1

d)

0 to (2^31) - 1

2.

What will be the output of the following code snippet?

#include <stdio.h>

int main() {

        int a = 3, b = 5;

        int t = a;

        a = b;

        b = t;

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

        return 0;

}

a)

3 5

b)

3 3

c)

5 5

d)

5 3

3.

How is an array initialized in C language?

a)

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

b)

int a = {1, 2, 3};

c)

int a[] = new int[3]

d)

int a(3) = [1, 2, 3];

4.

What is the output of the following code snippet?

#include <stdio.h>

int main() {

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

        int sum = 0;

        for(int i = 0; i < 4; i++) {

            sum += a[i];

        }

        printf("%d", sum);

        return 0;

}

a)

1

b)

4

c)

20

d)

10

5.

What is the output of the following code snippet?

int main() {

        int sum = 2 + 4 / 2 + 6 * 2;

        printf("%d", sum);

        return 0;

}

a)

2

b)

15

c)

16

d)

18

6.

How is the 3rd element in an array accessed based on pointer notation?

a)

*a + 3

b)

*(a + 3)

c)

(a + 3)

d)

&(a + 3)

7.

How are String represented in memory in C?

a)

An array of characters.

b)

The object of some class.

c)

Same as other primitive data types.

d)

LinkedList of characters.

8.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

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

    int sum = 0;

    for(int i = 0; i < 5; i++) {

        if(i % 2 == 0) {

            sum += *(a + i);

        }

        else {

            sum -= *(a + i);

        }

    }

    printf("%d", sum);

}

int main() {

        solve();

        return 0;

}

a)

2

b)

15

c)

Syntax Error

d)

3

9.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    int first = 10, second = 20;

    int third = first + second;

    {

        int third = second - first;

        printf("%d ", third);

    }

    printf("%d", third);

}

int main() {

        solve();

        return 0;

}

a)

10 30

b)

30 10

c)

10 20

d)

20 10

10.

What is the disadvantage of arrays in C?

a)

The amount of memory to be allocated should be known beforehand.

b)

Elements of an array can be accessed in constant time.

c)

Elements are stored in contiguous memory blocks.

d)

Multiple other data structures can be implemented using arrays.

11.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    int a = 3;

    int res = a++ + ++a + a++ + ++a;

    printf("%d", res);

}

int main() {

        solve();

        return 0;

}

a)

12

b)

24

c)

20

d)

18

12.

What will be the value of x in the following code snippet?

#include <stdio.h>

void solve() {

    int x = printf("Hello");

    printf(" %d", x);

}

int main() {

        solve();

        return 0;

}

a)

10

b)

5

c)

1

d)

0

13.

What does the following declaration indicate?

int x: 8;

a)

x stores a value of 8.

b)

x is an 8-bit integer.

c)

Both A and B.

d)

None of the above.

14.

Which of the following is the proper syntax for declaring macros in C?

a)

#define long long ll

b)

#define ll long long

c)

#define ll

d)

#define long long

15.

Which of the following is an exit controlled loop?

a)

While loop.

b)

For loop.

c)

do-while loop.

d)

None of the above.

16.

What is the size of the int data type (in bytes) in C?

a)

4

b)

8

c)

2

d)

1

17.

What will be the output of the following code snippet?

#include <stdio.h>

void swap(int a, int b) {

    int t = *a;

    a = b;

    *b = t;

}

void solve() {

    int a = 3, b = 5;

    swap(&a, &b);

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

}

int main() {

        solve();

        return 0;

}

a)

3 5

b)

5 3

c)

5 5

d)

3 3

18.

How to declare a double-pointer in C?

a)

int *val

b)

int **val

c)

int &val

d)

int *&val

19.

If p is an integer pointer with a value 1000, then what will the value of p + 5 be?

a)

1020

b)

1005

c)

1004

d)

1010

20.

What will be the output of the following code snippet?

#include <stdio.h>

#define VAL 3 * (2 + 6)

void solve() {

    int a = 10 + VAL;

    printf("%d", a);

}

int main() {

        solve();

        return 0;

}

a)

104

b)

24

c)

10

d)

34

21.

Which of the following are not standard header files in C?

a)

stdio.h

b)

stdlib.h

c)

conio.h

d)

None of the above.

22.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    printf("%d %d", (023), (23));

}

int main() {

    solve();

        return 0;

}

a)

023 23

b)

23 23

c)

19 23

d)

23 19

23.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    printf("%d %d %d", (076), (28), (0x87));

}

int main() {

    solve();

        return 0;

}

a)

76 28 87

b)

076 28 0x87

c)

62 28 135

d)

0 0 0

24.

What will be the result of the following code snippet?

#include <stdio.h>

void solve() {

    char ch[10] = "abcdefghij";

    int ans = 0;

    for(int i = 0; i < 10; i++) {

        ans += (ch[i] - 'a');

    }

    printf("%d", ans);

}

int main() {

    solve();

        return 0;

}

a)

45

b)

36

c)

20

d)

100

25.

What will be the output of the following code snippet?

#include <stdio.h>

void solve() {

    bool ok = false;

    printf(ok ? "YES" : "NO");

}

int main() {

    solve();

        return 0;

}

a)

Yes

b)

No

c)

Compilation Error

d)

None of the above