Week 1 Flashcards
What are the 7 fundamental features of C…?
Imperative : Focuses on how the program should achieve its goals.
Procedural : Program consists of a sequence of statements.
Compiled
Weak or Strong typed : Strong due to required type declaration, weak because accommodates type casting.
Statically typed : Types are checked before run time.
Portable : Compatibility on almost all modern machines. Is the native language of Unix.
Fast : Due to compiled nature and explicit memory management.
What does ANSI stand for? What was the purpose of making C ANSI standard?
American National Standards Institute. To ensure that C was portable, reliable and maintainable.
What does it mean that C has explicit memory management?
Programmers manually deal with memory management and garbage collection.
Give 2 cons of using C?
Does not have run time error checking.
Does not have sophisticated exception handling.
What is the process for compiling and linking C files?
- Compile all the .c and .h files. This converts them to machine readable object files.
- Link all the object files into one executable file.
- Run the executable file.
C is statically typed. What does this mean? What is the main advantage of this?
It means typing is checked at compile time. This provides protection from runtime errors.
What is the difference between a runtime error and a compile time error?
Runtime errors are errors that are not picked up by the compiler, and occur during running of the program, which causes a crash.
Compile time errors are usually semantic or syntactic errors which the compiler picks up and highlights before running. E.g int a = “Hello world” would leave to a compile time error.
What is the different between an initialised and un-initialised variable?
Un-initialised is declared but does not have any data assigned to it. Initialised is declared and has data assigned to it.
Give me 9 data types C uses… What is the bite size and range of each?
unsigned char: 1 byte, 0 to 255
char: 1 byte, -128 to 127
unsigned short int: 2 bytes, 0 to 65,535
short int: 2 bytes, -32,768 to 32,767
int : 4 bytes
float: 4 bytes
double: 8 bytes
long int: 8 bytes
long double: 16 bytes
What method can be used to get the number of bytes of a data type? Which pre-processor directive is it in?
stddef.h
sizeof( float )
Which pre-processor directive contains the symbolic constants that hold the maximum sizes of data types?
limits.h
CHAR_BIT -> Gives size of a character in bits
CHAR_MAX -> Gives max value of a char type etc.
List all the conversion characters for scanf…
%d -> decimal integer
%f -> floating point number (float)
%s -> string
%c -> char
%lf -> floating point number (double)
When printing, how would you write a print statement that outputs: * 5 *
printf(“%5d%5c”, x,’’);
When printing floats, the width and decimal places can be specified. What would the expression %10.2f output?
A floating point number with a field with of 10, and to 2 decimal places.
List all format specifies that can be used for printf…
%c -> character
%d -> decimal integer
%e -> floating point number in scientific notation
%f -> floating point number
%g -> use either e-format or f-formal, whichever is shorter
%s -> string