Systems Programming
60 flashcards · Other · by Lejla Becirovic
What are implicit type conversions?
If the result value does not fit into the result type, it is silently truncated.
What is a rvalue?
Value of the type stored
What is a lvalue?
Value of the memory location (the adress)
What are strings in C?
Arrays of char-type, written in double quotes and last element must be zero to indicate the end of the string
What different types of integers are there?
Decimal, hexadecimal (0x..), octal (0..), long and unsigned long
What is a pointer value and how do you define it?
A pointer value is a variable to hold an lvalue (adress) and it is defined by *.
Why do you give a type to a pointer variable?
The type refers to the type of data stored at the adress we will be storing in our pointer and thus the compiler knows how many bytes to copy into or out the memory location.
What are the three basic sections of the RAM?
Global variables, the heap (süace to dynamically allocate and managage memore -> to be done manually by programmer), the stack (managed by operating system -> local variables for functions)
How many bytes do ints, floats, doubles and chars take up?
4, 4, 8 and 1
What is the difference between *a and &a?
& to get a variable's adress (read only, adress-of operator), * to access an adress stored in a variable and is the de-referencing operator
How do we store the adress of our integer variable k to the pointer ptr?
ptr = &k;
How do we store the value 7 in k using the pointer?
*ptr = 7;
What does an array NOT have?
length information, range-checking
What is a structure?
A C structure is a compound data object and it consists of a collection of data objects of (possibly) different types.
What about the memory of a structure?
The declaration (without any instances) does not allocate any memory. So the symbol has size 0 memory and each instance will add up to the toal size of all structure members.
Can a variable and a tag in a structure have the same name?
Yes. (structure date date f.e)
What is the memory location of structure member?
It is defined as an offset.
How can u tell the compiler how many bits for a structure member you are going to use?
By adding a ":" after the member declaration.
What operations can be done on structures?
The only operations are "=" (assignment) and "&" (take the adress).
Why does *pmybday.year not work?
The dot operator has higher priority than * so use (*next).day instead.
What is the difference between an union and a structure?
The name of a structure member represents the offset of that member from the start of the structure while in a union all members start at the same location in memory.
What is the size of a union?
The biggest data in the union.
Does a change in one data member’s value have an impact on the value of other data members in an union?
Yes it has.
What are enums?
Enums are data items whose values may be any member of a symbolically declared set of values.
What does printing an enum result to?
Only a number.
Can an integer be assigned to an enum?
Yes and there are no checks made.
What is typedef?
You can create synonyms for types.
What is the difference between int main() and void main()?
int main() will return an integer exit code to the operating system
What is important to remember regarding the compiler and functions in C?
They need to be made known to the compiler before they can be invoked (compiler works from top to bottom!).
What is the best way to use functions in C?
Upfront of all other code put a line listing the functions expected to appear later (=prototype (only return and parameter TYPE NOT NAME).
What is the purpose of #inlcude <...>?
To provide prototypes for standard functions of the C library.
What are header files?
Nothing but huge collections of #define macros and function prototypes.
How many times is a stack frame created?
For each function called.
How does the calling convention _cdecl work?
Parameters are pushed on the stack in reverse order. The caller needs to clean up the stack.
What is the difference between having a pointer as parameter and normal value?
Having a pointer param remembers the inside change of the function and returns it, normal value does change inside the function but doesn't return it.
What is a variable declaration?
int a; is only a definition extern int a; is a correct delaration since it shows the compiler that "This is only a declaration; it's defined elsewhere"
What does the keyword "extern" mean?
It can mean that the definition is external to the file or that the definition occurs later in the file.
What do the variable type qualifiers "const" and "volatile" mean?
"const" is a write protected variable while "volatile" is a value that cannot be in any way optimized by compiler (const still can since value in memory can change).
How does the compiler push values into the stack?
From right to left.
If using a variable number of arguments in a function, what do you need?
You need at least one or more named parameter followed by ... .
How does a function iterate through the ... list of parameters?
By using macros va_start(pointer, length) to initiziale, va_arg to iterate and va_end to close the list.
How can you explain setjmp and longjmp easily?
These functions jump across several stackframes for exception or signal handling in JAVA setjmp for try and longjmp for catch.
Since you can write ptr = my_array instead of ptr = &my_array[10] what does that entail?
The name of the array is the address of the first element in the array.
Is my_array[i] the same as *(ptr + i)?
Yes
What is NULL?
The name of the macro used to initialize null pointers?
In the case of char my_string[40] how many bytes does the compiler set aside?
40 bytes of memory
What is the difference between char[] = "ABCDE" and char *cp = "FGHIJ" as local defintions?
The string ABCDE is stored on the stack, as is the value of the pointer cp but the string FGHIJ will be stored in the data section.
What can you write instead of (*st_ptr).age = 63;?
st_ptr->age = 63;
How can you compare a pointer of type int with a pointer of type char?
You can't compare them necessarily but you can compare them to a void pointer.
How do you declare a void pointer?
void *vptr;
What are the functions (int func(); , int *func(); , int (*func)() ; int *(*func) ();)?
function returning int, function returning pointer to int, pointer to function returning int, pointer to function returning pointer to int
Does (*(multi+row)+col) and multi[row][col] yield the same results?
No it has to be *(*(multi+row)+col).
Is multi[row] the same as *(multi + row)?
Yes.
What is **rowptr in context with arrays?
It is a pointer to a pointer to type int.
What is the use of malloc() and calloc()?
To allocate memory at run time.
When memory is allocated what does the allocating function return?
A pointer of type void *.
What do *malloc(size_t size) and *calloc(size_t num, size_t size) each reserve?
Malloc reserves size bytes while calloc reserves num*size bytes and initializes and bits to zero.
Is the value read from the console by scanf() returned by the function’s return value?
No, in C programming, the scanf() function returns the number of input items successfully matched and assigned, which can be less than the provided number of format specifiers. It returns an integer value indicating the number of input items assigned, or EOF if an error occurs or the end of the input stream is reached before any data could be successfully assigned.
Does the compiler perform type checking with macros?
When you use a macro, the preprocessor simply replaces all occurrences of the macro identifier with its corresponding definition in the source code. The preprocessor does not perform any type-checking or evaluation of expressions within macros
What are the rules of conditial operators regarding mixed types?
The rules of the conditional operator dictate that the type of the result should be the type to which both operands can be implicitly converted.