wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C program

Total questions: 54

Worksheet time: 27mins

Name
Class
Date
1.

What is a structure in C programming?

a)

A user-defined data type that allows you to combine data items of different types

b)

A type of loop in C programming

c)

A built-in function in C programming

d)

A special character in C programming

2.

The for loop in C can only be used when the number of iterations is known in advance

a)

False

b)

True

3.

What will be output?

int i=10;

int *p;

p=&i;

i+=5;

a)

i=10, *p=10

b)

i=15, *p=10

c)

i=10, *p=15

d)

i=15, *p=15

4.

#include <stdio.h>

void fun(int*p){

*p=10;

}

int main(){

int x=5;

fun(&x);

printf("%d", x);

return 0;

}

a)

address

b)

error

c)

10

d)

5

5.

If 2 strings are identical then what will function strcmp() returns?

a)

-1

b)

True

c)

0

d)

none of these

6.

Comments in C are ignored by the compiler and do not affect program execute

a)

True

b)

False

7.

What is the EXACT output from this code fragment?

int num=10;

if (num > 7 % 3 / 2 * 3);

printf("This is True");

else;

printf("This is False");

return 0;

a)

This is True

b)

This is False

8.

How would you get the value "6" out of the following array?

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

a)

a[0][2]

b)

a[2][0]

c)

a[3][1]

d)

a[1][3]

e)

a[0][3]

9.

How do you compare 2 strings in C?

a)

strcmp(str1,str2)

b)

str1.compare(str2)

c)

str1 == str2

d)

compare(str1,str2)

10.

The modulus operator cannot be used with a long double

a)

False

b)

True

11.

A pointer must be initialized before it is dereferenced

a)

False

b)

True

12.

What will be printed after Execution of the following program?

void main()

{

int a[5]={11,13,56,20,5};

a[2]=?

a)

13

b)

56

c)

20

d)

null value

13.

Each piece of data in an array is BEST described as a what?

a)

Item

b)

Elephant

c)

Integer and string

d)

Element

14.

What would be the size of the following union declaration? (Assuming size of double=8, int=4, char=1)

#include <stdio.h>

union uTemp

{

double a;

int b[10];

char c;

a)

8

b)

4

c)

40

d)

80

15.

The "=" operator is used for comparison in C

a)

False

b)

True

16.

The "printf()" function is used to read input from the keyboard

a)

False

b)

True

17.

The "const" keyword is used to declare variables whose values cannot be changed

a)

False

b)

True

18.

What symbol is used in conditional operators for AND

a)

AND

b)

&&

c)

&

19.

The fastest data access is provided using ____

a)

DRAM's

b)

Caches

c)

SRAM's

d)

Registers

20.

Arrays in C store elements in continuous memory locations

a)

False

b)

True

21.

Local variables are accessible throughout the entire program

a)

False

b)

True

22.

Given the code, what is in values [2][1]?

double [][] values = {{1.2,9.0,3.2},{9.2,0.5,-1.2},{7.3,7.9,4.8}}

a)

0.5

b)

7.3

c)

9.2

d)

7.9

23.

How do you declare a structure variable of type "Student" in C?

a)

struct Student studen1;

b)

Student student1;

c)

Student = student1;

d)

int student1;

24.

What is the output of the following printf?

int a=6,b=8;

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

a)

8

b)

0

c)

6

d)

14

25.

In C, strings are a built-in data types

a)

False

b)

True

26.

How do you access the member variables of a structure in C?

a)

Using the dot (.) operator

b)

Using the asterisk (*) operator

c)

Using the plus (+) operator

d)

Using the hash (#) operator

27.

The while loop checks its condition after executing the loop body

a)

True

b)

False

28.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

int a=5, b=-7, c=0, d;

d=++a && ++b ll ++c;

printf("\n%d%d%d%d", a, b, c, d);

}

a)

-6 -6 0 1

b)

6 -6 0 0

c)

6 -6 0 1

d)

6 -5 0 1

29.

Consider the declaration

char x[]="Applied_Informatics";

char *y="Applied_Informatics";

The output of puts(x) and puts(y) will be

a)

Different

b)

Will be the same

c)

Error

d)

Not related

30.

What will be the output of the C program?

#include <stdio.h>

int main()

{

a)

Compilation on error

b)

1

c)

2

d)

25

31.

Every C program must contain a main() function

a)

True

b)

False

32.

Which line of code is correct for the statement: Add 1 variable to x

a)

x+1

b)

x+x

c)

x++;

33.

The "printf()" function automatically adds a newline character after printing output

a)

False

b)

True

34.

What is right way to initialize array?

a)

int n{} = {2,4,12,5,45,5};

b)

int n(6) = {2,4,12,5,45,5};

c)

int n{6} = {2,4,12};

d)

int num[6] = {2,4,12,5,45,5};

35.

Which BEST describes an array?

a)

A data structure - Stores a collection of values under one name

b)

A list - Stores a list of strings

c)

A list - Stores a list of numbers

d)

A data collection - Stores a structure of values under one

36.

What will be the output of the C code?

#include <stdio.h>

int maint()

{

printf("Hello World! %d\n", x);

return 0;

}

a)

Hello World! followed by a junk value

b)

Hello World!

c)

Hello World! x;

d)

Compile error

37.

A global variable is automatically initialized to zero if not explicitly initialized

a)

True

b)

False

38.

Which of the following correctly accesses the seventh element stored in arr, an array with 100 elements?

a)

arr[7]

b)

arr{7}

c)

arr{6}

d)

arr[6]

39.

In C, function arguments are passed by value by default

a)

True

b)

False

40.

What is the significance of the 'sizeof' operator in relation to structures in C?

a)

It is used to determine the size of a structure in bytes

b)

It is used to determine the color of the structure

c)

It is used to calculate the sum of elements in a structure

d)

It is used to find the maximum value in a structure

41.

What is the value of this expression using integer arithmetic:

7/4

a)

2

b)

1.75

c)

1

42.

The 'sizeof' operator returns the size of a variable or data type in bytes

a)

True

b)

False

43.

A variable declare as "int *p"; can store the address of an integer variable

a)

True

b)

False

44.

____ is the user-defined datatype

a)

float

b)

int

c)

array

d)

enum

45.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

char *s = "hello";

char *p = s;

printf("%c\t%c", p[0], s[1]);

}

a)

h h

b)

Run time error

c)

h e

d)

h l

46.

What will be printed on the screen from this fragment:

int num=0;

printf("%d", ++num);

a)

1

b)

2

c)

0

47.

A segmentation fault can occur if a program accesses invalid memory

a)

False

b)

True

48.

what is the value of y?

int x=5;

y=x++;

a)

6

b)

0

c)

4

d)

5

49.

Toán tử tam phân nào dưới đây là đúng để tìm số lớn nhất giữa a và b?

a)

max = (a > b) : a ? b;

b)

if (a > b) ? a : b;

c)

max = (a > b) ? a : b;

d)

max = a > b ? b : a;

50.

Biểu thức (8 >> 2) có kết quả bằng bao nhiêu?

a)

32

b)

2

c)

4

d)

0

51.

Kết quả của phép toán (5 ^ 5) là bao nhiêu?

a)

0

b)

1

c)

10

d)

5

52.

Giá trị của x sau khi thực hiện: int x = 10; x >>= 1;

a)

9

b)

20

c)

1

d)
5
53.

Nếu x = 6 (110) và y = 3 (011), kết quả của x ^ y là bao nhiêu?

a)

4

b)

7

c)

5

d)

2

54.

Biểu thức (a += b) tương đương với cách viết nào?

a)

b = b + a

b)

a + b = a

c)

a = a + b

d)

a = b