Week 1 Flashcards

1
Q

What are the 7 fundamental features of C…?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does ANSI stand for? What was the purpose of making C ANSI standard?

A

American National Standards Institute. To ensure that C was portable, reliable and maintainable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does it mean that C has explicit memory management?

A

Programmers manually deal with memory management and garbage collection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give 2 cons of using C?

A

Does not have run time error checking.
Does not have sophisticated exception handling.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the process for compiling and linking C files?

A
  1. Compile all the .c and .h files. This converts them to machine readable object files.
  2. Link all the object files into one executable file.
  3. Run the executable file.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

C is statically typed. What does this mean? What is the main advantage of this?

A

It means typing is checked at compile time. This provides protection from runtime errors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between a runtime error and a compile time error?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the different between an initialised and un-initialised variable?

A

Un-initialised is declared but does not have any data assigned to it. Initialised is declared and has data assigned to it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Give me 9 data types C uses… What is the bite size and range of each?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What method can be used to get the number of bytes of a data type? Which pre-processor directive is it in?

A

stddef.h
sizeof( float )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which pre-processor directive contains the symbolic constants that hold the maximum sizes of data types?

A

limits.h
CHAR_BIT -> Gives size of a character in bits
CHAR_MAX -> Gives max value of a char type etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

List all the conversion characters for scanf…

A

%d -> decimal integer
%f -> floating point number (float)
%s -> string
%c -> char
%lf -> floating point number (double)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When printing, how would you write a print statement that outputs: * 5 *

A

printf(“%5d%5c”, x,’’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When printing floats, the width and decimal places can be specified. What would the expression %10.2f output?

A

A floating point number with a field with of 10, and to 2 decimal places.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

List all format specifies that can be used for printf…

A

%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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How would you compile and link the files fileOne.c fileTwo.c into one executable called myProgram in 2 terminal commands?

A

gcc -c fileOne.c fileTwo.c
gcc fileOne.o fileTwo.o -o myProgram

17
Q

Talk through the process of compiling and linking using GNU compiler gcc

A

Run gcc, which checks the source code tokens for semantic or syntactic errors.
Upon succesful compilation, object files for each source file is created.
The object files can then be linked using gcc into one executable file.

18
Q

What are the 6 tokens that the compiler analyses when checking the source code? If an issue is found, what happens?

A

constants, string constants, keywords, identifiers, operators, punctuation.
A compile time error is raised if an issue is found.

19
Q

When 3rd party libraries are being used, what adjustment should be taken in the compilation step?

A

Add command library expression to the end of the command line argument.

20
Q

How do the loader and compiler components differ within the compilation system?

A

The compiler analyses the source code, creates object code of each source file. The loader then links these filers into one executable program.