Comp2 midterm Flashcards
What escape character is used to print a backslash?
\
What escape character prints a double quote marks?
"
How do you convert an integer to a float in a calculation?
float average = (float)total/count;
Syntax for enum.
enum Name {VALUE, VALUE, VALUE};
//defines enum class Name with three
//values. Values are constant.
enum Name VariableName;
//creates an enum variablename of type name.
Syntax for passing a function to a function where the inputted functions takes two arguments a and b which are also arguments to the original function. (prototype).
How would the function be called?
void functionName( int , int , void (*otherFunction)(int, int) );
functionName(a , b, function being inputted )
inside functionname: (*otherFunction)(a, b) calls otherFunction
How can an array of pointers be created?
char *a[4] = {“”, “”,””,””}
//Can store strings of any size.
Define an array of three functions to pointers with functions named 1 2 and 3. All these functions return type int and take in two ints.
How would said function be called given inputs a and b and function choice = a variable called number?
int (*f[3])(int , int ) = {function1, function2, function3}
(*f[number])(a, b);
What is the end of file character on windows?
ctrl + Z
What function reads from a sequential file (give syntax)? What function writes to a sequential file (give syntax)?
fscanf(file, type, variable);
fprintf(file, type, variable);
What function checks for end of file symbol?
feof(stdin) or feof(file pointer)
How is a pointer to a file created and opened?
FILE *cfPtr;
cfPtr = fopen(“name.txt”, “type”);
Different access types for files.
w = open for writing (replaces files or creates new)
r = open for reading (for existing files)
a = open for appending (existing files and creates)
r+,a+,w+ = open for all three
b added for binary modes.
How is the file position pointer reset?
rewind(file pointer name)
What functions read and write to files of random access type?(with syntax)
fread(&nameofvariabletoberead, sizeof(type of variable being read), 1, file pointer name)
fwrite(&nameofvariabletobewritten, sizeof(type of variable being written), 1, file pointer name)
Syntax for fseek function?
fseek(file pointer name, index * sizeof(struct), SEEK_SET);
where index starts at 0.
For the third argument of fseek, what is it? Explain the three possible values.
Is where the offset calculated by fseek starts from.
SEEK_SET = start of file
SEEK_CUR = current position in file
SEEK_END = end of file
What does the # mean in code?
Pre-processor command, processed before complimation
What is the \ in \n called?
the escape character
What are the four stages of processing code in order?
Pre-processing
Compiling
Linking
Loading
What is the file called after linking?
An executable
What is the coercion of arguments?
Forcing of arguments to be the appropriate type.
Arrange the order from lowest to highest in terms of C arithmetic conversion rules.
(a) char (b) float (c) double (d) int
Highest: Double
Float
Int
Lowest: Char
What does LIFO stand for?
Last In First Out
What is a stack frame?
An individual entry on the stack that holds a function’s address and its variables.