Font size
WorksheetsCSS101 Week 10
Total questions: 20
Worksheet time: 7mins
Which statement about struct in C is correct?
A struct can only contain one data type
typedef must always be used with struct
struct can group variables of different data types
To confuse beginners
struct cannot be copied directly with = operator
Which is the correct way to declare a variable of this struct?
struct Student s1
Student s1
typedef Student s1
new Student s1
old Student s1
What keyword is used to define a new data type name for an existing structure?
define
typedef
alias
strcpy()
Which function must be used to assign strings to struct members of type char[]?
strcpy()
printf()
myFunction()
stdio.h
strcat()
What’s the main purpose of enum in C?
Store multiple data types together
Create dynamic arrays
Renames your variable so your lecturer can’t find it
Create a list of named integer constants
To make your code look like a menu
Which of the following is valid enum usage? (Select all that apply)
enum Color {RED, GREEN, BLUE};
enum {int LOW, int HIGH};
enum Level = {LOW=10, HIGH=20};
typedef enum {SMALL=1, MEDIUM=2, LARGE=3} Size;
What header must be included for file handling in C?
<stdlib.h>
<file.h>
<stdio.h>
<ctype.h>
<thisisnotreal.h>
What does FILE *fptr; represent?
File name
Pointer to a file structure
Character pointer
File type
What happens if you open a file in "w" mode and it already exists?
Write a new 'Hello World' message into the file
The file remains unchanged
The file content is overwritten
Whispers new data into the file
Why should you close a file with fclose()? (Select all that apply)
Saves any changes to the file
Frees memory used by the file pointer
Prevents file deadlocks
Because your lecturer said so
To reuse the file later
Which file opening mode appends new data to an existing file?
"a"
"A"
'a'
"w"
"rw"
What will happen if you open a file with "r" mode and it does not exist?
A new file is created
Program crashes
fopen() returns NULL
The OS automatically restart
What does the & operator do in C?
Returns the value of a variable
Returns the address of a variable
Dereferences a pointer
What does the * operator do when used with pointers?
Accesses the value stored at the address
Multiplies the value
Converts int to float
Accesses the address stored in a variable
What happens if you dereference an uninitialized pointer?
It will return 0
It will automatically allocate memory
The program will crash or behave unpredictably
The program will crash silently
What does int *p = &x; mean?
p stores the value of x
p is equal to x
p stores the address of x
In pass by value, what is passed to the function?
Pointer to memory location
Reference to original variable
Copy of the variable’s value
In pass by reference, what is passed to the function?
A constant copy
The variable’s value
A deep copy of the variable
The variable’s memory address
What output is produced by the code below?
10
20
Compile error
0x7ffee4bff5ac
