Programming - C Flashcards

(28 cards)

1
Q

Why is lower level programming needed?

A

To more precisely control use of memory and other resources and to produce high performance code with minimal overheads

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

Why is C a low-level, high-level language?

A

High level because we can write code in natural language.
Low level because we can precisely control use of and access to memory

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

What type of language is C?

A

Compiled

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

What are the broad stages of compilation?

A

Compiling and linking

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

What are the properties of the C programming language?

A

Direct memory access
Efficient compilation
Minimal run-time support
Procedural programming paradigm
Simple, minimal syntax

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

What are the primitive data types in C?

A

int, float, char

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

What is the difference between static vs dynamic typing?

A

Static typing = The type of a variable is determined at compile time and remains fixed
Dynamic typing = The type of a variable is determined at run-time and can change

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

What is the difference between strong and weak typing?

A

Strong typing = The type of a variable must be declared, Different types of variables cannot be mixed

Weak typing = The type of a variable need not to be declared, Different types of variables can be combined

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

What type of typed language is C?

A

statically typed and weakly typed

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

What are the properties of variables in C?

A

The value – data stored in the variable
The address – location in memory of the variable

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

What is a pointer?

A

A pointer is a datatype that can store a memory address

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

What are the properties of a pointer?

A

The value – a location in memory
The target – item stored at that memory location

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

What are the properties of a stack?

A

The stack – memory reserved for static program data

  • Managed by the compiler
  • A list-in-first-out (LIFO) data structure
  • Used for statically declared variables and arrays
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the properties of the heap?

A

The heap – memory available for dynamic program data

  • Access to heap memory is through pointers
  • Flexible unordered address space
  • Used for dynamically declared variables and arrays
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the two parts of scanf()?

A

the format statement and the variable address

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

When do you use for loops?

A

Known number of iterations
Array traversal
Numeric sequences

17
Q

When do you use while loops?

A

Unknown number of iterations
Condition based repetition
Pre-test loop structure – may execute zero times
E.g. input validation

18
Q

When do you use do-while loops?

A

Unknown number of iterations
Condition based repetition
Post test loop structure – body must execute once
E.g. input validation where prompt comes first, menu systems

19
Q

What is parsing?

A

Analysing a string
Splitting the string into tokens often according to defined rules

20
Q

What types of typed is functions?

21
Q

What is the definition of a function?

A

Also called a signature or prototype
Defines the inputs and outputs but not the implementation
For library functions this is generally what is provided plus documentation

22
Q

What is the single responsibility principle?

A

SRP is a software design guideline that states “each function in a program should have only one responsibility or purpose”.

23
Q

What type of call-by language is C?

A

call-by-value

24
Q

What does array pointer duality mean?

A

Arrays can behave like pointers (on the stack)
The name of the array is the address in memory

25
What can structures in C contain?
Different primitive data types Arrays of primitive types Pointers Other structures
26
What is a self-referential structure?
the structure contains a pointer of its own type
27
What are include guards needed in header files?
Prevents multiple definitions (compilation errors) Handles circular dependencies Improves compilation efficiency
28
What is the compilation process?
1. Preprocessing: handle #include, #define, etc 2. Compiling: translate .c files to object files (.o) 3. Linking: combine object files into executable