NEW
Font size
WorksheetsTech Tournament SF-1
Total questions: 20
Worksheet time: 30mins
What is the output of the following code snippet? int x = 5; printf("%d", x+++x);
10
11
12
Undefined behavior
What is the size of the following structure on a 64-bit system with default alignment? struct Test { char a; int b; char c; };
6 bytes
9 bytes
12 bytes
16 bytes
What is the result of (unsigned char)~0?
0
255
-1
Undefined
What does the expression x & (x-1) evaluate to when x is a power of 2?
x
x-1
0
1
What is the result of malloc(0) in C?
Returns NULL
Returns a valid pointer
Compilation error
Implementation-defined
What does x ^= y; y ^= x; x ^= y; accomplish?
Swaps values of x and y
Sets both to zero
Undefined behavior
Multiplies x and y
What is the defined behavior of the following code according to the C standard? int i = 5; printf("%d %d", ++i, i++);
It prints 7 6
It prints 6 5
It prints 7 5
The behavior is undefined
What is the most likely output of this program?
#include
Hello!
A compilation error
A null string
Undefined behavior (garbage value or crash)
On a 64-bit system with standard memory alignment, what will sizeof(struct Test) return? struct Test { char a; double b; int c; };
13 bytes
16 bytes
24 bytes
12 bytes
What is the output of this code?
#include
x > y
x <= y
Compilation Error
Runtime Error
What does the declaration int (*(*foo)(void))[10]; define?
foo is a pointer to a function that returns a pointer to an array of 10 integers.
foo is a function that returns a pointer to an array of 10 integer pointers.
foo is a function that returns a pointer to a pointer to an array of 10 integers.
foo is a function returning an array of 10 pointers to integers.
Which statement correctly allocates memory for struct Message to hold a 20-character string?
Message *m = malloc(sizeof(Message) + 20);
Message *m = malloc(sizeof(Message));
Message *m = malloc(sizeof(int) + 20);
This struct cannot be legally instantiated.
In which context does the name of an array NOT decay into a pointer to its first element?
When passed to a function.
When used with the * (dereference) operator.
When used as an operand of the sizeof operator.
When used in an arithmetic expression.
What is the output of the preprocessor?
PASTE(value, 12)
value12
100
"value12"
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;
4 bytes
8 bytes
12 bytes
5 bytes
What is the primary difference between const int *p and int * const p?
No difference, they are interchangeable.
const int *p is a pointer to a constant integer; int * const p is a constant pointer to an integer.
const int *p is a constant pointer; int * const p is a pointer to a constant.
The first is illegal syntax; the second is valid.
What is the output of the following program?
#include
49
17
27
12
What will this program print?
sizeof=5, strlen=5
sizeof=6, strlen=5
sizeof=6, strlen=6
sizeof=5, strlen=6
What is the value of WED in this enumeration? enum Days {SUN, MON, TUE=5, WED, THU, FRI};
2
3
5
6
Which expression checks if an integer n is odd?
n | 1
n1
n & 1
n % 2 != 0
