wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

ch456713

Total questions: 99

Worksheet time: 1hrs 14mins

Name
Class
Date
1.

What is an lvalue in C?

a)

A) A label name

b)

B) A literal constant

c)

C) An object stored in computer memory

d)

D) An error message

2.

What does the statement count++ do?

a)

Sets count to 0

b)

Increments count by 1

c)

Multiplies count by 2

d)

Decreases count by 1

3.

Which of the following is a correct use of assignment chaining?

a)

i + j + k = 0;

b)

i == j == k == 0;

c)

i = j == k = 0;

d)

i = j = k = 0;

4.

What is the output of

i = 8; j = 4; i *= j++;

printf("%d %d", i, j); ?

a)

32 4

b)

40 5

c)

40 4

d)

32 5

5.

Which form of increment returns the incremented value immediately?

a)

x--

b)

--x

c)

++x

d)

x++

6.

In a switch statement, what data types can the controlling expression be?

a)

int, char, enum

b)

array

c)

string and float

d)

float and double

7.

What is the output if grade = 3 ?

switch (grade) { case 4: printf("Excellent"); case 3: printf("Good"); case 2: printf("Average"); case 1: printf("Poor"); case 0: printf("Failing"); }

a)

GoodAveragePoorFailing

b)

Good

c)

GoodAverage

d)

GoodAveragePoor

8.

Which Unix command is used to move or rename a file?

a)

cd

b)

mv

c)

rm

d)

cp

9.

What does rm -i do?

a)

Removes files with confirmation

b)

Moves files

c)

Copies files

d)

Renames files

10.

How can you clear the terminal screen?

a)

Ctrl + l

b)

rm screen

c)

clear + l

d)

Ctrl + c

11.

Which relational operator has lower precedence than ?

a)

==

b)

=<

c)

>

d)

<

12.

What is the output of

i=3; j=2; k=1;

printf("%d", i<=j==j);

a)

A) 0

b)

B) 1

c)

C) true

d)

D) false

13.

Which operator is unary?

a)

A) >=

b)

B) ||

c)

C) &&

d)

D) !

14.

Which of these tests if a value is between i and k?

a)

i<j<k

b)

i<j && j<k

c)

i>j || j<k

d)

i==j<k

15.

Which of these if statements assigns 0 to i and skips the block?

a)

if (i != 0)

b)

if (i++)

c)

if (i == 0)

d)

if (i = 0)

16.

Which keyword ends a case in a switch?

a)

stop

b)

return

c)

break

d)

end

17.

What happens if a switch case is missing a break?

a)

It stops the switch

b)

The program exits the switch

c)

A syntax error occurs

d)

It continues into the next case

18.

Which header file provides bool type in C99?

a)

A) stdbool.h

b)

B) stdio.h

c)

C) stdlib.h

d)

D) string.h

19.

Which of these represents the correct form of if for multiple statements?

a)

if (expression) { statements }

b)

if expression (statements)

c)

if expression { statements }

d)

if (expression): statements

20.

Which of these statements is true about scanf and format strings?

a)

Scanf expects input to match non-whitespace characters in the format string.

b)

Scanf ignores any input that doesn't match the format string.

c)

Scanf uses default values for missing inputs.

d)

Scanf always reads all input, even if it's incorrect.

21.

What Unix text editor is guaranteed to be available on most systems?

a)

nano

b)

vi

c)

code

d)

emacs

22.

Which command in vi saves and quits?

a)

A) :q!

b)

B) :w

c)

C) :wq

d)

D) :quit

23.

In a while loop, when is the controlling expression evaluated?

a)

After each iteration except the first

b)

Only once at the start

c)

After the loop body executes

d)

Before the loop body executes

24.

What happens when a while Loop controlling expression is always true?

a)

Syntax error

b)

The loop will execute only once

c)

The loop won't execute

d)

Infinite loop

25.

Which statement is true about a do-while loop?

a)

The expression is tested before the loop body executes

b)

The expression must always be true

c)

The loop body executes at least once

d)

It cannot contain break statements

26.

What is the output of this C code?

for (n = 9; n != 0; n--)

printf("%d ", n--);

a)

9 7 5 3 3

b)

9 7 5 3 1

c)

9 8 7 6 5 4 3 2 1

d)

8 6 4 2

27.

Which operator is used to separate multiple expressions in a for loop?

a)

&

b)

,

c)

:

d)

;

28.

What is the correct command to delete a line in vi?

a)

p

b)

yy

c)

dd

d)

u

29.

Which C loop structure is best for counting iterations?

a)

for

b)

do-while

c)

while

d)

switch

30.

Which keyword exits the innermost loop or switch?

a)

continue

b)

stop

c)

break

d)

return

31.

Which keyword skips to the next iteration of the loop?

a)

break

b)

goto

c)

pass

d)

continue

32.

What is the output of this C code?

sum=0; for(i=0;i<3;i++){

if(i%2==1) break; sum+=i; }

a)

1

b)

5

c)

3

d)

0

33.

What is the output of this C code?

sum=0; for(i=0;i<3;i++){

if(i%2==1) continue; sum+=i; }

a)

3

b)

0

c)

1

d)

2

34.

What is a null statement?

a)

An empty statement marked by a semicolon

b)

A statement with only a label

c)

An incomplete declaration

d)

A statement with variables but no operation

35.

In which loop is this commonly seen: for (;;) ?

a)

To loop a fixed number of times

b)

To exit a loop immediately

c)

To count up to 10

d)

To create an infinite loop

36.

What is the output of this code?

i=3; while(i>0); { printf("%d ", i); --i; }

a)

A) 3 2 1 0

b)

B) Does not compile

c)

C) 3 2 1

d)

D) Infinite loop

37.

Which command pastes a copied line in vi?

a)

yy

b)

p

c)

dd

d)

rm

38.

Which loop construct guarantees the loop body executes at least once?

a)

do-while

b)

for

c)

switch

d)

while

39.

In vi, how do you undo the last action?

a)

:undo

b)

ctrl+z

c)

:back

d)

u

40.

Which command in vi allows you to copy a line?

a)

:wq

b)

mv

c)

yy

d)

dd

41.

What is the correct format specifier for printing an unsigned int?

a)

%ld

b)

%d

c)

%i

d)

%u

42.

Which type conversion is safest to prevent data loss?

a)

Converting float to int

b)

Converting char to int

c)

Converting double to float

d)

Converting int to long

43.

Which format specifier is used to print a long int?

a)

%d

b)

%ld

c)

%f

d)

%hd

44.

Which of the following is an unsigned int?

a)

short int

b)

int

c)

long int

d)

unsigned int

45.

What is integer overflow?

a)

An arithmetic result is too large to represent

b)

A variable is too large to store in memory

c)

An error in scanf

d)

The program crashes

46.

What is the correct way to prevent overflow when multiplying two ints?

a)

i = (long)(j * j);

b)

i = j * (long)j;

c)

i = (long) j * j;

d)

i = j * j;

47.

Which cast will convert an int to double in division?

a)

(double)dividend / divisor

b)

(float)dividend / divisor

c)

(int)dividend / divisor

d)

(long)dividend / divisor

48.

Which floating type in C offers the highest precision?

a)

extended

b)

long double

c)

float

d)

double

49.

How do you specify a float constant explicitly?

a)

3.14F

b)

F3.14

c)

3.14

d)

3.14L

50.

What does the typedef typedef int Bool; do?

a)

Changes bool's size

b)

Makes a new integer type

c)

Creates a type alias for int

d)

Defines a macro

51.

Which header defines types like size_t?

a)

limits.h

b)

typedefs in the C standard library

c)

stdio.h

d)

string.h

52.

What is the ASCII value of 'A'?

a)

97

b)

48

c)

32

d)

65

53.

Which of these reads a single character using scanf?

a)

scanf("%c", &ch);

b)

scanf("%s", &ch);

c)

scanf("%f", &ch);

d)

scanf("%d", &ch);

54.

How does getchar() differ from scanf()?

a)

It reads one character, including whitespace

b)

It reads an entire line

c)

It skips white space

d)

It returns a char

55.

Which loop skips characters until a newline using getchar()?

a)

do { ch = getchar(); }

while (ch != '\n');

b)

while (ch != ' ');

c)

do { ch = getchar(); }

while (ch == '\n');

d)

do { ch = getchar(); }

while (ch == ' ');

56.

What is the purpose of toupper(ch)?

a)

Tests if a character is alphabet

b)

Converts character to lowercase

c)

Converts character to uppercase

d)

Converts a number to character

57.

Which header must be included to use toupper()?

a)

string.h

b)

ctype.h

c)

stdio.h

d)

stdbool.h

58.

Which format specifier is used to print a float value?

a)

%ld

b)

%f

c)

%c

d)

%d

59.

Which of the following is a character constant?

a)

'A'

b)

"A"

c)

A

d)

char A

60.

What is the output of: char ch = 'b'; ch = ch + 3; ?

a)

'k'

b)

'u'

c)

'd'

d)

'e'

61.

What does int a[10]; do in C?

a)

Declares an integer with value 10

b)

Declares an array of 10 integers

c)

Initializes 10 arrays with default values

d)

Allocates memory dynamically for 10 variables

62.

Why is #define N 10 often used when declaring arrays?

a)

It makes code easier to debug

b)

It allows easy updates to array size

c)

It improves runtime performance

d)

It automatically initializes the array

63.

Which of these is a valid way to initialize an array?

a)

array a = [1, 2, 3];

b)

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

c)

int a[] = 10;

d)

int a = {1, 2, 3};

64.

What happens if you access an array index outside its declared size in C?

a)

The program stops automatically

b)

It results in undefined behavior

c)

It wraps around to index 0

d)

It gives a compile-time error

65.

What is the index of the first element in a C array?

a)

0

b)

-1

c)

Depends on the array type

d)

1

66.

What is stored in an array if it's only partially initialized?

a)

Compile-time error

b)

Random values

c)

Previous values in memory

d)

Remaining elements are set to 0

67.

What type of loop is commonly used to traverse an array?

a)

for loop

b)

while loop

c)

do-while loop

d)

switch loop

68.

What happens when you assign a value to a[5] in a 5-element array?

a)

It causes undefined behavior

b)

It gives a warning

c)

It stores at the last element

d)

It returns 0

69.

What is the correct syntax to read values into an array?

a)

scanf("%d", &a);

b)

scanf(a[i]);

c)

scanf("%d", &a[i]);

d)

scanf("%d", a);

70.

What is the maximum index in int b[100]; ?

a)

98

b)

99

c)

100

d)

101

71.

How are array elements stored in memory in C?

a)

Reversed

b)

Randomly

c)

Alternating

d)

Contiguously

72.

Which of the following is NOT allowed?

a)

int a[] = {1,2};

b)

x[2] = 5;

c)

int x[10];

d)

int b[0];

73.

Can arrays be returned directly from a function in C?

a)

Yes, as arrays

b)

No, arrays are constants

c)

Yes, using structs only

d)

No, but you can return a pointer

74.

Which operator is used to access array elements?

a)

. (dot)

b)

&

c)

[] (brackets)

d)

->

75.

What does the following do? int a[2] = {5};

a)

Sets a[0] = 5, a[1] = 0

b)

Skips initialization

c)

Initializes all to 5

d)

Causes an error

76.

How are 2D arrays declared in C?

a)

array a(3,4);

b)

int a[3,4];

c)

int a = [3][4];

d)

int a[3][4];

77.

What is the row-major order in C?

a)

Reverse storage

b)

Bitwise mapping

c)

Row-wise storage

d)

Column-wise storage

78.

Can a 2D array be partially initialized?

a)

Yes, and remaining elements become 0

b)

No

c)

Only for first row

d)

Yes, and rest stay uninitialized

79.

How many elements are in int x[][3] = {{1,2,3},{4,5,6}};?

a)

3

b)

9

c)

0

d)

2 rows, 3 columns → 6 elements

80.

What is the output of this code?

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

printf("%d", a[1]);

a)

Garbage value

b)

0

c)

2

d)

1

81.

What will sizeof(a) return in this code?

int a[5];

Assume int is 4 bytes.

a)

8

b)

10

c)

4

d)

20

82.

How can you initialize all values of an integer array to zero?

a)

int a[5] = {0};

b)

int a = {0};

c)

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

d)

int a[5] = 0;

83.

What’s the correct way to loop through an array a[5]?

a)

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

b)

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

c)

for(i=1;i<5;i++)

d)

for(i=1;i<=5;i++)

84.

What is printed by this code?

int arr[] = {4, 5, 6};

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

a)

4

b)

Garbage value or crash

c)

5

d)

6

85.

Which of these is valid syntax to pass an array to a function?

a)

void foo(int arr[]);

b)

void foo(int arr[10]);

c)

void foo(int* arr);

d)

All of the above

86.

Can you assign arrays directly in C like arr1 = arr2;?

a)

Only for character arrays

b)

Yes

c)

Only for static arrays

d)

No, must copy element-by-element

87.

How do you declare a 2D array of 3 rows and 4 columns?

a)

array[3,4];

b)

int a[4][3];

c)

int a[12];

d)

int a[3][4];

88.

How are arrays passed to functions?

a)

By reference (as pointers)

b)

By address copy

c)

By value

d)

Not allowed

89.

What is printed by this?

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

int *p = a;

printf("%d", *(p + 2));

a)

2

b)

1

c)

Error

d)

3

90.

Which function can copy arrays safely in C?

a)

assign()

b)

memcpy()

c)

strcpy()

d)

alloca()

91.

What is the actual type of a string literal like "abc" when declared in C?

a)

char[]

b)

string

c)

char *

d)

int *

92.

What type does a string literal like "abc" decay to when used in an expression or passed to a function in C?

a)

char[]

b)

char *

c)

int *

d)

string

93.

How many bytes are set aside for the string "abc" in memory?

a)

8

b)

5

c)

It depends on the compiler

d)

4

94.

What character is used to mark the end of a string in C?

a)

\n

b)

\0

c)

\e

d)

\t

95.

Which of the following creates a null pointer to a string (i.e., not pointing to any string)?

a)

char s[] = "";

b)

char *s = NULL;

c)

char *s = "\n";

d)

char s[] = "NULL";

96.

Which of the following correctly defines an empty string (a null string containing only '\0')?

a)

char *s = NULL;

b)

char s[] = "NULL";

c)

char *s = "\n";

d)

char s[] = "";

97.

What will the following code do?

char *p = "abc";

*p = 'z';

a)

Change 'a' to 'z'

b)

Produce a warning

c)

Cause undefined behavior

d)

Compile but do nothing

98.

What does this declaration define: char date1[8] = "June 15";

a)

An incomplete array

b)

A char pointer

c)

A character array with a null terminator

d)

A string literal

99.

What size must a character array have to hold an 80-character string?

a)

81

b)

83

c)

79

d)

80