-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVectors_DMA.txt
72 lines (55 loc) · 2.15 KB
/
Vectors_DMA.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
VECTOR:
vector<dataType> name({ value1, value2, value3 ....});
vector<dataType> name(size, value);
vector<dataType> arrayName;
DataType here can be of type className.
We can create array of elements each of type a class.
vector also starts with index 0.
CLASS:
Class must have both private and public sections.
STRUCT:
Same as class but donot have any public and private sections. All are public by default.
To access the values or functions of the class or struct:
call it as -- classElement.value
-- classElement.function
To CALL CONSTRUCTOR:
// calling inside the class method-1
ClassName(): variable(value) {}
// calling inside the class method-2
ClassName (list-of-parameters){
// assigning values or instructions
}
// calling outside the class
<class-name>::<class-name>(list-of-parameters){
// assigning values or instructions
}
To CALL DESTRUCTOR:
// calling inside the class
~ClassName() {
//some instructions
}
// calling outside the class
ClassName :: ~ClassName(){
//some instructions
}
DYNAMIC MEMORY ALLOCATION::
FOR CREATING A BLOCK OF MEMORY:
int *p = NULL;
p = new int;
(or)
int *p= new int;
(or for an array)
int *p = new int[10];
We can give this pointer a new allocation of the data
FOR REMOVING THE ALLOCATED VARIABLE:
delete pointer-variable; // programmer responsibility to delete the dynamically allocated memory
(or)
delete[] p; // deletes the array pointed by the p
ERRORS IN DYNAMIC ALLOC:
int *p = new(nothrow) int[10]; //if the allocation fails it shows error of type bad_alloc
// to get rid of that error and let the program cntinue we use this
// alloc fails when there is not space for the new alloc
// in that case it alloc the new one to nullptr and let the program run.
EXPLANATION ABOUT NEW KEYWORD:
int *b= new int; // this shows that the new keyword gives new pointer to particular storage of memory
// when we say new int , b contains the address of the new 4 bits storage allocated, it points to the first bit.