Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Logic Gates and Boolean Algebra Problems 3.1-3.3

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

Consider the C code shown in the image: #include int main(){ printf("Hello World"); return 0; } What will be printed to the console?

a)

Nothing prints

b)

Hello World 0

c)

"Hello World"

d)

Hello World

2.

Which header file must be included to use printf() and scanf() in a C program?

a)

b)

c)

d)

3.

On a typical 32-bit or 64-bit system, which pairing of C data type and size is most appropriate?

a)

double → 4 bytes

b)

int → 2 bytes

c)

char → 1 byte

d)

float → 8 bytes

4.

Given int a = 5, b = 2; what does printf("%d", a / b); output?

a)

2.5 because it keeps fraction

b)

3 because it rounds to nearest

c)

0 because division needs casting

d)

2 because integer division truncates

5.

Which statement best defines a pointer in C?

a)

A constant storing immutable data

b)

An operator that multiplies numbers

c)

A function returning an integer value

d)

A variable holding a memory address

6.

Select the correct syntax to declare a pointer to an int named ptr.

a)

int *ptr;

b)

int ptr*;

c)

*int ptr;

d)

pointer int ptr;

7.

Consider the code: int a = 10; printf("%d %d", a++, ++a); What is the most appropriate evaluation of this statement in standard C?

a)

It prints 10 12 reliably on all compilers

b)

It is undefined behavior due to multiple increments

c)

It prints 11 11 consistently for defined sequence

d)

It is implementation-defined but still well-defined

8.

In C, what does writing return 0; at the end of main() indicate to the operating system?

a)

Program paused awaiting user input

b)

Program ended with a failure status code

c)

Program ended successfully with status zero

d)

Program skipped returning any status

9.

What is the output of the following code snippet: int x = 10; printf("%d", x++ + ++x);?

a)

21

b)

19

c)

20

d)

22

10.

Which of the following correctly initializes an array of 10 integers in C?

a)

int arr{10};

b)

int arr[10];

c)

int arr(10);

d)

int arr = new int[10];

11.

What will be the output of the following code: char str[] = "Hello"; printf("%c", str[1]);?

a)

H

b)

l

c)

o

d)

e

12.

What will be the output of the following code snippet: int y = 3; printf("%d", y * 2);?

a)

5

b)

6

c)

3

d)

8

13.

Given float f = 5.5; what does printf("%.1f", f); output?

a)

6

b)

5.50

c)

5.5

d)

5

14.

What will be the output of the following code: int arr[] = {1, 2, 3}; printf("%d", arr[2]);?

a)

1

b)

0

c)

2

d)

3

15.

Which of the following correctly describes the use of the 'sizeof' operator in C?

a)

It is a function to convert data types

b)

It is used to allocate memory dynamically

c)

It returns the number of elements in an array

d)

It returns the size of a variable in bytes

16.

What is the output of the following code snippet: int a = 5; int b = 10; printf("%d", a + b);?

a)

15

b)

5

c)

50

d)

10

17.

What is the output of the following code: int x = 7; printf("%d", x % 3);?

a)

3

b)

0

c)

2

d)

1

18.

Which of the following correctly describes the purpose of the 'break' statement in C?

a)

It exits a loop or switch statement

b)

It terminates the program immediately

c)

It pauses the execution of the program

d)

It skips the current iteration of a loop

19.

What will be the output of the following code: float a = 5.0; float b = 2.0; printf("%.0f", a / b);?

a)

2.5

b)

3

c)

2

d)

5

20.

What is the result of the following code: int a = 5; int b = 3; printf("%d", a - b);?

a)

1

b)

15

c)

8

d)

2

21.

Which of the following correctly declares a function that returns a float in C?

a)

void myFunction(float);

b)

float myFunction();

c)

float: myFunction;

d)

myFunction() float;

22.

What will be the output of the following code: int x = 4; printf("%d", x * x);?

a)

4

b)

16

c)

8

d)

2

23.

What will be the output of the following code: int a = 10; int b = 5; printf("%d", a % b);?

a)

10

b)

5

c)

0

d)

2

24.

Which of the following correctly defines a structure in C?

a)

struct myStruct { int a; };

b)

struct myStruct(int a);

c)

struct myStruct: int a;

d)

myStruct struct { int a; };

25.

What will be the output of the following code: char c = 'A'; printf("%c", c + 1);?

a)

1

b)

C

c)

A

d)

B