Com2 (till test 2)(Ignore for final)) Flashcards
What is a self-referential struct?
Contains a pointer member that points to a structure of the same structure type.
Syntax for assigning array/pointer with malloc.
newPtr = malloc(sizeof(what it is pointing to))
Library for exit function.
include <stdlib.h></stdlib.h>
What are the two symbolic constants for the exit function?
EXIT_SUCCESS
EXIT_FAILURE
What is the library for signals?
<signal.h>
</signal.h>
What two arguments does the signal function receive? How are singals raised?
A function, and a symbolic constant that will call the function when triggered.
Using the raise function with a symbolic constant as parameter.
Labels and goto syntax?
labelname:
goto labelname;
How can CTRL Z be simulated with raise function?
raise(SIGINT);
What do labels do when the compiler reads them?
Nothing.
Bubble sort syntax. (Lecturer’s way)
for(unsigned int pass = 1; pass < SIZE; ++pass){
for(size_t i = 0; i < SIZE - 1; ++i){
if (a[i] > a[i + 1]){
int hold = a[i];
a[i] = a[i + 1];
a[i + 1] = hold;
}
}
}
Binary search syntax.
while (low <= high) {
size_t middle = (low + high) \ 2;
if (target == b[middle]){
return middle;
}
else if (target < b[middle]){
high = middle - 1;
}
else {
low = middle + 1;
}
}
Library for malloc, realloc and calloc?
include <stdlib.h></stdlib.h>