Lecture 2 - C Basics Flashcards
Is C object-oriented?
No
What is the difference between Java and C when OOP is ignored?
How memory is managed and how the program is executed.
What does -Werror do?
Turns all warnings into errors making the program impossible to compile until all warnings have been fixed.
What does the -Wall flag do?
The -Wall flag enables most compiler warnings
What are make files?
Files that allow building of C programs automatically -> with a command.
Are make files C exclusive?
No, they can be used for any command line interface command.
What is the first line of a make file made up of?
[targets] : [sources]
- sources can be thought of as dependencies
What does typing make in the CLI do?
Execute the first command in the make file.
What does every C program have ?
An entry function called main.
Do we need to return anything from a main function?
No, 0 is automatically returned by the function.
0 indicates successful execution
What does a non-negative value returned from main indicate?
unsuccessful execution
What are the 2 versions of main?
int main() { … }
int main(int argc, char* argv[]) { … }
What is a C programming language?
A statically typed language where every variable must have a data type known without running the program.
What are data types?
A label which gives meaning to its stored in memory.
What do we control when choosing a specific data type?
The amount of memory we use, as different data types take up different amount of space.
How do booleans work in C?
0 is false and anything else is true. The data type is int.
What do data types help with ?
Preserving meaning to computations and results.So only meaningful computations can be completed.
Size of char?
1 byte
Size of short / unsigned short?
2 bytes = 16 bits
Size of int / unsigned int?
4 bytes = 32 bits
Size of long / unsigned long?
4 or 8 bytes
Size of long long / unsigned long long?
8 bytes
What does the <stdbool.h> inclusion give us?</stdbool.h>
The ability to have a defined type of boolean (bool) in C99.
These are defined as macros
What is a {} called in C?
A block
What does {} introduce?
A lexical scope/
What must be unique in a lexical scope?
Variable names
What are the 3 ways of allocating variables?
- automatic (declared in a local block)
- static (declared at file level - outside all blocks). Lifetime is the entire execution of program.
- allocated (the ones we dynamically requested)
Do we need to manage memory for automatic variables?
No, it happens automatically.
What is a struct ?
Structure which consists of members which could be of different data types.
How are members in a struct stored in memory?
Next to each other (sequentially)
What does every string end with in C?
\0, it is added automatically
What is a function definition?
fully specifies the behaviour of a function
What is a function declaration?
the interface describing how a function can be used
What searches for functions when they’re not in source file (they could be in different file or library).
The linker
How are arguments passed to functions in C and what does this mean?
Call by value , we pass a copy of arguments to function (except arrays and pointers).