wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CSS101 Week 10

Total questions: 20

Worksheet time: 7mins

Name
Class
Date
1.

Which statement about struct in C is correct?

a)

A struct can only contain one data type

b)

typedef must always be used with struct

c)

struct can group variables of different data types

d)

To confuse beginners

e)

struct cannot be copied directly with = operator

2.

Which is the correct way to declare a variable of this struct?

a)

struct Student s1

b)

Student s1

c)

typedef Student s1

d)

new Student s1

e)

old Student s1

3.

What keyword is used to define a new data type name for an existing structure?

a)

define

b)

typedef

c)

alias

d)

strcpy()

4.

Which correctly assigns a value to its fields?

a)

date.day = 10;

b)

date->day = 10;

c)

*date.day = 10;

d)

date(day) = 10;

e)

scanf ("%d", &day);

5.

Which function must be used to assign strings to struct members of type char[]?

a)

strcpy()

b)

printf()

c)

myFunction()

d)

stdio.h

e)

strcat()

6.

What’s the main purpose of enum in C?

a)

Store multiple data types together

b)

Create dynamic arrays

c)

Renames your variable so your lecturer can’t find it

d)

Create a list of named integer constants

e)

To make your code look like a menu

7.

Which of the following is valid enum usage? (Select all that apply)

a)

enum Color {RED, GREEN, BLUE};

b)

enum {int LOW, int HIGH};

c)

enum Level = {LOW=10, HIGH=20};

d)

typedef enum {SMALL=1, MEDIUM=2, LARGE=3} Size;

8.

What header must be included for file handling in C?

a)

<stdlib.h>

b)

<file.h>

c)

<stdio.h>

d)

<ctype.h>

e)

<thisisnotreal.h>

9.

What does FILE *fptr; represent?

a)

File name

b)

Pointer to a file structure

c)

Character pointer

d)

File type

10.

What happens if you open a file in "w" mode and it already exists?

a)

Write a new 'Hello World' message into the file

b)

The file remains unchanged

c)

The file content is overwritten

d)

Whispers new data into the file

11.

Why should you close a file with fclose()? (Select all that apply)

a)

Saves any changes to the file

b)

Frees memory used by the file pointer

c)

Prevents file deadlocks

d)

Because your lecturer said so

e)

To reuse the file later

12.

Which file opening mode appends new data to an existing file?

a)

"a"

b)

"A"

c)

'a'

d)

"w"

e)

"rw"

13.

What will happen if you open a file with "r" mode and it does not exist?

a)

A new file is created

b)

Program crashes

c)

fopen() returns NULL

d)

The OS automatically restart

14.

What does the & operator do in C?

a)

Returns the value of a variable

b)

Returns the address of a variable

c)

Dereferences a pointer

15.

What does the * operator do when used with pointers?

a)

Accesses the value stored at the address

b)

Multiplies the value

c)

Converts int to float

d)

Accesses the address stored in a variable

16.

What happens if you dereference an uninitialized pointer?

a)

It will return 0

b)

It will automatically allocate memory

c)

The program will crash or behave unpredictably

d)

The program will crash silently

17.

What does int *p = &x; mean?

a)

p stores the value of x

b)

p is equal to x

c)

p stores the address of x

18.

In pass by value, what is passed to the function?

a)

Pointer to memory location

b)

Reference to original variable

c)

Copy of the variable’s value

19.

In pass by reference, what is passed to the function?

a)

A constant copy

b)

The variable’s value

c)

A deep copy of the variable

d)

The variable’s memory address

20.

What output is produced by the code below?

a)

10

b)

20

c)

Compile error

d)

0x7ffee4bff5ac