Week 1 - Basics Flashcards

1
Q

Is C imperative or declarative?

A

Imperative

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

What is the difference between imperative and declarative programming languages?

A

Imperative describes computation in terms of statements that change a program state, e.g. C.

Declarative describes computation in terms of what is should accomplish, e.g. SQL.

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

Is C object-oriented or procedural/functional?

A

Procedural/functional

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

Is C compiled or interpreted?

A

Compiled

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

C is statically, weakly typed - what does this mean?

A

Statically typed - types are checked before runtime (must declare variables before you use them).

Weakly typed - supports implicit type conversions.

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

How do you declare a comment in C?

A

/* this is a comment */

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

What does it mean when the main() function returns 0?

A

Success - everything else normally means failure.

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

What is the statement #include <stdio.h> called, what part is the header file, and what is it used for?</stdio.h>

A

A compiler directive - used for including a library (in this case I/O with stdio.h, which is the header file)

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

What header file is needed for standard I/O (input/output)?

A

stdio.h

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

What is the process of turning a .c file into an executable program?

A

Source (.c or .h) compiles to object (.o or .obj), which is linked to executable (.exe)

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

What is the standard compile?

A

gcc -ansi -c myProgram.c -o myProgram.o
(note -ansi not necessarily required)

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

What is the standard link?

A

gcc myProgram.o -o myProgram

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

How can several object files be linked together?

A

gcc myProgram.o mySubroutines.o -o myProgram

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

What do make and makefiles do?

A

Utility for building executables and libraries from source code (compiling). They define how to compile and link files to build an executable. They only regenerate intermediate files when necessary.

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

What is the header file for using mathematical functions (e.g. sqrt)?

A

math.h

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

What does linking/loading do?

A

Linking combines object files and libraries into a single executable file, so performs other tasks, such as generating symbol tables that map the program’s symbols to their addresses in memory. Loading loads the executable file into memory and prepares it for execution. It allocates memory for the program’s code, data, and stack. The loader also performs tasks such as resolving any dynamic links to shared libraries and initializing the program’s global variables.

Often invoked by GCC itself:
gcc circle.o radius.o -o circle -lm

17
Q

How do you include a library when linking/loading?

A

-l for a library, e.g. -lm for the maths library.

18
Q

How do you compile and link in one go?
Use two files circle.c and radius.c, with main() in circle.c which uses the maths library.

A

gcc circle.c radius.c -o circle -lm

19
Q

What are the basic non-decimal data types in C, their sizes, and their range?

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 -> -2,147,483,648 to 2,147,483,647
Long int - 8 bytes -> +/- 9 x 10^18

20
Q

What are the decimal data types in C, their sizes, their smallest and largest values and their precision?

A

Float - largest value is +/- 3.4 x 10^38, smallest is +/- 3.4 x 10^-38, precision is 6 digits

Double - largest value is +/- 1.07 x 10^308, smallest is +/- 1.07 x 10^-308, precision is 15 digits

Long double - 16 bytes -> largest value is +/- 3.4 x 10^4932, smallest is +/- 3.4 x 10^-4932, precision is 18 digits

21
Q

What is the header file needed to include minimum and maximum values of data types?

A

limits.h

22
Q

What is the header file needed to include the function sizeof()?

A

stddef.h

23
Q

What is the null character in C?

A

nullCharacter = ‘\0’

24
Q

How would you print the char variable ‘myChar’?

A

printf(“%c”, myChar)

25
Q

How do you print an int stored in variable myInt in C?

A

printf(“%d”, myInt)

26
Q

How do you print a float/double/long double variable stored in f in C?

A

printf(“%f”, f)

27
Q

How do you write an if-then-else statement in C?

A

if (<condition>)
{</condition>

<statement>
}
else if (<condition>)
{
<statement>
}
else
{
<statement>
}
</statement></statement></condition></statement>

28
Q

There are no explicit boolean datatypes in ANSI C. What is done instead?

A

Conditions are evaluated to int values -> 0 is false, anything else is true.

29
Q

What do the symbols || and && mean?

A

‘or’ and ‘and’

30
Q

How do you write a for loop in C?

A

for (<initialisation>; <condition>; <increment>)
{...}</increment></condition></initialisation>

31
Q

In a for loop in C, what do break and continue do?

A

Break jumps to the first statement after the end of the loop.

Continue jumps to the start of the next iteration.

32
Q

How do you write a while and a do while loop in C, and what is the difference between them?

A

while (<condition>)
{...}</condition>

do
{…}
while (<condition>);</condition>

A do while loop always runs the loop once; a while loop only runs if the condition is initially met.