Você está na página 1de 6

MTRN2500

C & C++
1. The memory model of a computer: Stack, Data, Code, Heap:

https://en.wikipedia.org/wiki/Code_segment
Data segment:
contains any global or static variables which have a predefined value and can be
modified.

any variables that are not defined within a function (global) or are defined in a
function but are defined as static so they retain their addresses across subsequent
calls.
e.g. in C
int val = 3;
char string [ ] = hello world;
the values for these variables are initially stored within the read-only memory
(typically within .text) and are copied into the .data segment during the start-up
routine of the program.
Heap segment:
commonly begins at the end of the .bss and .data segments and grows to larger
addresses from there (grows upwards).
heap area is managed by malloc, calloc, realloc, and free.
shared by all threads, shared libraries, and dynamically loaded modules in a process.
Stack segment:
A LIFO structure (last in, first out), typically located in the higher parts of memory.
A stack pointer register tracks the top of the stack; adjusted each time a value is
pushed onto the stack.
The set of values pushed for one function call is called a stack frame
Generally grows in the opposite direction of the heap segment (grows downwards),
when they both meet, free memory is exhausted.
stack grows towards address zero (going down), meaning more recent items, deeper
in the call chain, are at numerically lower addresses and are closer to the heap.

2. All C/C++ programming constructs:


for, do-while, while
if, if-else
switch-case-break-default
break, continue
3. Fundamental data types: https://www.tutorialspoint.com/cprogramming/c_data_types.htm
char, short, int, long, unsigned char, unsigned short, unsigned int, unsigned long

float, double, long double

void

4. Writing basic procedural functions


5. Dynamic memory allocation: http://www.cplusplus.com/doc/tutorial/dynamic/
new - to request memory
Dynamic memory is allocated using operator new. new is followed by a data type
specifier and, if a sequence of more than one element is required, the number is
represented in square brackets [ ]. syntax:
pointer = new type; //allocates memory to contain one single element of type
type
or
pointer = new type [number_of_elements]; // allocates a block (array) of
elements of type type where number_of_elements is an integer value to specify the
amount
this allocates memory from the heap for one type data
delete - to free up memory
delete pointer ; //releases memory of a single element allocated using new
delete [ ] - to free up memory
delete [ ] pointer; //releases memory allocated for arrays of elements using new and
the contents of the brackets [ ] is the size
NULL
6. Pointers: https://www.tutorialspoint.com/cprogramming/c_pointers.htm
to fundamental data types, syntax:
char *pointer = NULL; //creates a pointer to a char data type which is NULL-initialised
int *IntPtr = &a; //creates a pointer to integer type initialised to address of a
to arrays, 1D, 2D, 3D
double dereferencing, triple de-referencing to get the value of the first cell in a 2D or
3D array
to functions

declaration ex: int (*CalcFunctionPtr)(int, int);


CalcFunctionPtr is the name of the function pointer
This specifies that the function to be pointed to by CalcFunctionPtr must receive two
integer parameters and must return an integer value
to objects
use of pointers in dynamic memory allocations
7. Creating user defined structures and classes
struct, union, class
struct: user-defined composite types typically used to only store data, default visibility
for all member functions and data is public
union: similar to structs, but inheritance is not allowed and the memory is shared
between member variables.
class: typically used for advanced compositions, often have an arrangement of public
and/or private member functions and data

public, protected and private access attributes

public: accessible by everybody


protected: accessible by the class, its descendants, and friends
private(default): accessible by the class and friends

member data and member functions


virtual, friend, operator, and pure virtual functions
static member data and static member functions
constructor, copy constructor and destructor
what does a constructor do and what does a destructor do?
how copy constructors work
all compiler generated default constructors
all compiler overloaded operators
8. Developing class hierarchies
use of virtual functions
use of virtual destructors
use of abstract classes
9. Pass through objects
pass by reference
pass by value
return by reference
return by value
10. Class derivation and inheritance
11. Abstract classes. How to distinguish between abstract classes and non-abstract classes.
virtual functions
pure virtual functions
use of base class pointers
12. Overloading
function overloading
operator overloading
o as member functions
o as non-member functions
o use of friend functions
13. Function templates and class templates
syntax of templates
use of templates

container class vector


iterating through vector of objects
accessing object data using iterators
14. Type casting
ordinary type casting
dynamic_cast
15. Streams
how data are packed as bytes
how to alter data packing in memory
instantiating stream objects for input and output
writing object data to an ASCII file
writing object data to a binary file
reading object data from ASCII file
reading object data from a binary file
how to randomly access data in binary file

Você também pode gostar