wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Tech Tournament SF-1

Total questions: 20

Worksheet time: 30mins

Name
Class
Date
1.

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

a)

10

b)

11

c)

12

d)

Undefined behavior

2.

What is the size of the following structure on a 64-bit system with default alignment? struct Test { char a; int b; char c; };

a)

6 bytes

b)

9 bytes

c)

12 bytes

d)

16 bytes

3.

What is the result of (unsigned char)~0?

a)

0

b)

255

c)

-1

d)

Undefined

4.

What does the expression x & (x-1) evaluate to when x is a power of 2?

a)

x

b)

x-1

c)

0

d)

1

5.

What is the result of malloc(0) in C?

a)

Returns NULL

b)

Returns a valid pointer

c)

Compilation error

d)

Implementation-defined

6.

What does x ^= y; y ^= x; x ^= y; accomplish?

a)

Swaps values of x and y

b)

Sets both to zero

c)

Undefined behavior

d)

Multiplies x and y

7.

What is the defined behavior of the following code according to the C standard? int i = 5; printf("%d %d", ++i, i++);

a)

It prints 7 6

b)

It prints 6 5

c)

It prints 7 5

d)

The behavior is undefined

8.

What is the most likely output of this program? #include char* get_string() { char str[] = "Hello!"; return str; } int main() { char *p = get_string(); printf("%s\n", p); return 0; }

a)

Hello!

b)

A compilation error

c)

A null string

d)

Undefined behavior (garbage value or crash)

9.

On a 64-bit system with standard memory alignment, what will sizeof(struct Test) return? struct Test { char a; double b; int c; };

a)

13 bytes

b)

16 bytes

c)

24 bytes

d)

12 bytes

10.

What is the output of this code? #include int main() { unsigned int x = 1; signed char y = -1; if (x > y) printf("x > y"); else printf("x <= y"); return 0; }

a)

x > y

b)

x <= y

c)

Compilation Error

d)

Runtime Error

11.

What does the declaration int (*(*foo)(void))[10]; define?

a)

foo is a pointer to a function that returns a pointer to an array of 10 integers.

b)

foo is a function that returns a pointer to an array of 10 integer pointers.

c)

foo is a function that returns a pointer to a pointer to an array of 10 integers.

d)

foo is a function returning an array of 10 pointers to integers.

12.

Which statement correctly allocates memory for struct Message to hold a 20-character string?

a)

Message *m = malloc(sizeof(Message) + 20);

b)

Message *m = malloc(sizeof(Message));

c)

Message *m = malloc(sizeof(int) + 20);

d)

This struct cannot be legally instantiated.

13.

In which context does the name of an array NOT decay into a pointer to its first element?

a)

When passed to a function.

b)

When used with the * (dereference) operator.

c)

When used as an operand of the sizeof operator.

d)

When used in an arithmetic expression.

14.

What is the output of the preprocessor?

a)

PASTE(value, 12)

b)

value12

c)

100

d)

"value12"

15.

On a 32-bit system, what is the most likely sizeof this struct? typedef struct { unsigned int a : 5; unsigned int b : 20; unsigned int : 0; unsigned int c : 4; } BitStruct;

a)

4 bytes

b)

8 bytes

c)

12 bytes

d)

5 bytes

16.

What is the primary difference between const int *p and int * const p?

a)

No difference, they are interchangeable.

b)

const int *p is a pointer to a constant integer; int * const p is a constant pointer to an integer.

c)

const int *p is a constant pointer; int * const p is a pointer to a constant.

d)

The first is illegal syntax; the second is valid.

17.

What is the output of the following program? #include #define SQUARE(x) x * x int main() { printf("%d", SQUARE(5 + 2)); return 0; }

a)

49

b)

17

c)

27

d)

12

18.

What will this program print?

a)

sizeof=5, strlen=5

b)

sizeof=6, strlen=5

c)

sizeof=6, strlen=6

d)

sizeof=5, strlen=6

19.

What is the value of WED in this enumeration? enum Days {SUN, MON, TUE=5, WED, THU, FRI};

a)

2

b)

3

c)

5

d)

6

20.

Which expression checks if an integer n is odd?

a)

n | 1

b)

n1n ^ 1

c)

n & 1

d)

n % 2 != 0