Part 1 - Introduction Flashcards
What are the 6 phases of developing a program in C++?
1) Edit
2) Preprocess
3) Compile
4) Link
5) Load
6) Execute
What is a member function?
A method of a class
When is a default no argument constructor generated?
If we do not provide our own constructor for the class
How many bits does a char have?
8
How many bits does a short have?
16
How many bits does a long have?
32
How many bits does an int have?
Usually 32
How many bits does a long long have?
64
How many bits does a float have?
32
How many bits does a double have?
64
How many bits does a long double have?
128
What 3 areas are data stored in during execution?
static area
stack
heap
What is the static area used for?
Storing items whose lifetime is the duration of the program
What is the stack used for (wrt data storage)?
Local variables in functions, whose lifetime is the invocation of a function
What is the heap area used for?
Dynamic items whose lifetime is controlled by the programmer
What 6 elements does a variable have?
Type - primitive or classes
Lifetime - how long it exists for
Scope - what can see it while it is alive
Name
Size (in memory)
Value
What are the 5 storage classes?
Automatic - for local variables existing only when the block in which the variables are defined is active
Register - for local variables, fast access, rarely used
Mutable - for class members to make them always modifiable even in a const function or a member of a const object
External - to make the variable globally accessibly within the program
Static - for variables that last the entire lifetime of the program
How many times can a static variable or class be initialised?
Once
Why does the auto keyword rarely need to be used?
Local variables are usually stored on the stack anyway so will only be alive while the function is executing
What constraints does a const member function have?
Cannot change values of members of the object to which it is applied
What must be done with a static variable when it is declared?
Initialised with a value
Where must a global variable be defined?
How is it then accessed from other files?
Outside of any class or function
extern int a; at the top of the file or header
In this code fragment:
int a = 0; // global
……
int myFunc() {
char a = ‘x’;
……
};
How would the global variable be accessed from within myFunc()?
::a