Programming - C Flashcards
(28 cards)
Why is lower level programming needed?
To more precisely control use of memory and other resources and to produce high performance code with minimal overheads
Why is C a low-level, high-level language?
High level because we can write code in natural language.
Low level because we can precisely control use of and access to memory
What type of language is C?
Compiled
What are the broad stages of compilation?
Compiling and linking
What are the properties of the C programming language?
Direct memory access
Efficient compilation
Minimal run-time support
Procedural programming paradigm
Simple, minimal syntax
What are the primitive data types in C?
int, float, char
What is the difference between static vs dynamic typing?
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
What is the difference between strong and weak typing?
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
What type of typed language is C?
statically typed and weakly typed
What are the properties of variables in C?
The value – data stored in the variable
The address – location in memory of the variable
What is a pointer?
A pointer is a datatype that can store a memory address
What are the properties of a pointer?
The value – a location in memory
The target – item stored at that memory location
What are the properties of a stack?
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
What are the properties of the heap?
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
What are the two parts of scanf()?
the format statement and the variable address
When do you use for loops?
Known number of iterations
Array traversal
Numeric sequences
When do you use while loops?
Unknown number of iterations
Condition based repetition
Pre-test loop structure – may execute zero times
E.g. input validation
When do you use do-while loops?
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
What is parsing?
Analysing a string
Splitting the string into tokens often according to defined rules
What types of typed is functions?
statically
What is the definition of a function?
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
What is the single responsibility principle?
SRP is a software design guideline that states “each function in a program should have only one responsibility or purpose”.
What type of call-by language is C?
call-by-value
What does array pointer duality mean?
Arrays can behave like pointers (on the stack)
The name of the array is the address in memory