wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Hackharbor 3.0 Day 4:C

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What is the key difference between a structure and a union in C?

a)

Structure shares memory among members, union does not

b)

Union shares memory among members, structure does not

c)

Structure allows only one member, union allows multiple

d)

Both allocate memory exactly the same way

2.

What does a struct say to a union at a party?

a)

“I like my space, you share yours”

b)

“Youʼre occupying my memory!”

c)

“Letʼs combine and confuse the compiler!”

d)

“Letʼs be friends forever!”

3.

Which operator is used to access members of a structure variable in C?

a)

meow

b)

. (dot)

c)

&

d)

*

4.

Which of the following keywords is used to define a user-defined data type combining different data types?

a)

class

b)

union

c)

struct

d)

typedef

5.

What will happen if you assign a value to one member of a union and then assign another value to a different member?

a)

Both values get stored separately

b)

The latter assignment overwrites the first value

c)

Compiler error

d)

Both values remain unchanged

6.

Why are structure members always calm?

a)

Because they each have their own space to chill

b)

They work too hard to care

c)

They donʼt share memory, so no conflicts

d)

They meditate regularly

7.

In a union, what is the size of the memory block allocated?

a)

Sum of all membersʼ sizes

b)

Size of the smallest member

c)

Size of the largest member

d)

None of the above

8.

Why did the union break up with the structure?

a)

They fought over memory space

b)

The structure was too possessive with data

c)

Union wanted to share but structure kept everything separated

d)

Because union was always changing personalities!

9.

Which file mode opens a file for writing only and creates the file if it does not exist?

a)

r

b)

w

c)

a

d)

r+

10.

If a file could talk, what would it say when closed?

a)

“Thanks for the RAM!”

b)

“Donʼt forget to fclose me!”

c)

“Iʼm done, go to sleep!”

d)

“Hey coder, save me!”

11.

Which function is used to close a file in C?

a)

fclose()

b)

closefile()

c)

file_close()

d)

close()

12.

Which function reads formatted input from a file?

a)

fread()

b)

fscanf()

c)

fgets()

d)

freadf()

13.

A file pointer walks into a bar and orders a drink. The bartender says:

a)

"Sorry, Iʼm not a pointer!"

b)

"Hereʼs to reading and writing!"

c)

"You look lost, where you wanna go?"

d)

"Do you want to rewind or seek?"

14.

If you try to read a file that doesnʼt exist, the file would:

a)

Cry with tears of NULL pointers

b)

Shout “Error!”

c)

Just silently ignore you

d)

Call your mom

15.

Which function writes formatted output to a file?

a)

fwrite()

b)

fprintf()

c)

fputs()

d)

fprintf_s()

16.

What does fseek(fp, 0, SEEK_SET) do?

a)

Moves file pointer to end

b)

Moves file pointer to beginning

c)

Moves file pointer 0 bytes from current position

d)

None of the above

17.

What will happen if you try to read beyond the end of a file?

a)

Error occurs

b)

Returns EOF or 0

c)

File pointer resets

d)

File is deleted

18.

How can you reset the file pointer back to the start of the file?

a)

fseek(fp, 0, SEEK_END

b)

rewind(fp)

c)

ftell(fp)

d)

fclose(fp)

19.

If a structure contains an array member, how do you assign a string to that array?

a)

person.name = "Alice";

b)

strcpy(person.name, "Alice");

c)

person.name.str = "Alice";

d)

memcopy(person.name, "Alice");

20.

What is the purpose of typedef when used with structs?

a)

To make a new data type alias

b)

To declare an integer

c)

To release memory

d)

To write a function prototype

21.

What happens to other membersʼ values in a union when you store data in one member?

a)

Remain unchanged

b)

Undefined / overwritten

c)

Increase in size

d)

Compiler throws error

22.

Selecting the wrong mode in fopen, for example opening a file with "r" when you intend to write, will:

a)

Allow writing anyway

b)

Result in runtime error

c)

Create the file automatically

d)

Fail to open the file (return NULL

23.

Which of the following is true about nested structures?

a)

A structure cannot contain another structure

b)

Nested structures share same memory space

c)

A structure can include another structure as a member

d)

Nested structures require a union

24.

Whatʼs the minimum number of members a structure can have?

a)

0

b)

1

c)

2

d)

Unlimited but must have 3 minimum

25.

Which of these snippets properly declares a union?

a)

union { int a; char b; };

b)

struct union { int a; char b; };

c)

unite { int a; char b; };

d)

union Data() { int a; float b; };

26.

Which function is best to copy strings to a structure member array?

a)

strcpy()

b)

memcpy()

c)

strcat()

d)

strcpy_s()

27.

What file mode should be used to append to a file without deleting its previous content?

a)

w

b)

a

c)

r

d)

r+

28.

If you want to read an entire line including spaces from a file, which function is preferable?

a)

fscanf()

b)

fgets()

c)

fread()

d)

fprintf()

29.

Which of the following can NOT be done with a union?

a)

Store multiple types but only one at a time

b)

Store multiple members simultaneously with independent values

c)

Reduce memory usage when storing alternative data

d)

Share memory space for different data types

30.

Which file mode would a sneaky hacker use to sneak in quietly?

a)

"r" – reading quietly

b)

"w" – leaving a trace

c)

"a" – sneaking in to add notes at the end

d)

"r+" – best of both worlds!