C family Flashcards
(280 cards)
Why can C be referred to as being almost a portable assembly language
It is as close to the machine as possible while it is almost universally available for existing processor architectures.
What does the statement “C is imperative” mean?
It describes computation in terms of statements that change a program state
What does the statement “C is declarative” mean?
describes computation in terms of what it should accomplish
C is a procedural/functional language
What does the statement “C is weakly typed” mean?
C supports implicit type conversion
What does the statement “C is statically typed” mean?
Types are checked before runtime so variables must be declared
What are compiler directives and some examples?
Special instructions that guide the preprocessor
#include will include the contents of another file - usually containing function prototypes and variable declarations
What is the difference between float, double and long double
While they are both floating point numbers, double is larger and long double is larger still
How much memory does a char, short int, int and long int take up?
char - 1 byte
short int - 2 bytes
int - 4 bytes
long int - 8 bytes
(unsigned versions take up the same amount of memory)
To what precision can a float, double and long double hold data and how much memory do they take up?
Float, 6 digits, 4 bytes
double, 15 digits, 8 bytes
long double, 18 digits, 16 bytes
As there is no boolean datatypes in ANSI C, how are conditions evaluated?
0 is considered false while any other value is considered true
How can i create AND and OR conditional statements
Double ampersand for AND: &&
Double straight liney thing for OR: ||
What is an advantage and disadvantage of using code short-hands
Adv: reduce time to type - may reduce codesize
DisAdv: do not execute any faster and may make code harder to follow
What do break and continue statements do?
Break will break out of the loop and jump to the next command
Continue will jump to the start of next iteration
What is the difference between a While and a Do While loop?
While loop will check the condition before executing
Do While will execute once before checking the condition is true
What does “pass by value” mean for functions in C
The value of the variable is passed into the function and the value can be used in further calculations. The value of the original variable is not changed
f(variable_name)
What does “pass by reference” mean for functions in C
A pointer to the variable is passed to the function, that way processing can be done on the variable and it’s actual value will change
f(*variable_name)
How can we get around C’s functions only being able to return one value if we want to change multilpe
Through the use of pointers, if multiple pointers are fed into the function then the values of multiple variables can be changed
How should we pass arguments into the main function from the command line?
It must be defined like this:
int main(int argc, char **argv)
Arg c contains the number of arguments passed and argv is an array of string values. This is not required but is suggested heavily by convention
What are the values of argv if the program is called myProgram
myProgram Hello 3 “a short sentence”
argv[0] = myProgram
argv[1] = Hello
argv[2] = 3
argv[3] = a short sentence
What are two advantages to using pointers to functions?
Functions can be passed as arguments to other functions, oft called callback functions
We can choose which function to execute at runtime based on user inputs
There’s something about qSort on lecture 3 but cba to figure it out
How are arrays stored in memory?
Arrays are stored contiguously in memory, when an array is initialized an appropriate amount of memory will be reserved
How are strings stored in C and what does it mean for a string to be unitialised?
A string is stored contiguously as an array of characters, ending in a NULL terminating character ‘\0’.
An string is uninitialized if it hasn’t had characters assinged to it and will contain random stuff until it does
What is a null terminator and what will happen if one does not exist?
The null terminator (‘\0’) tells printf when to stop printing out characters
If your string does not have a null terminator, printf carries on plodding through memory and printing out characters until it encounters one.