-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray.cpp
57 lines (45 loc) · 1.04 KB
/
Array.cpp
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
#include "stdafx.h"
#include <iostream>
#include <string>
#include <unordered_map>
#include <bitset>
#include <memory>
#include <array>
using namespace std;
// Collection of variable, same type
class Entity {
int ex[5];
public:
static const int mySize = 5;
int myArr[mySize];
std::array<int, 5> anotherArray; // C++ 11
Entity() {
for (int i = 0; i<5; i++){
ex[i] = 2;
}
}
};
int main() {
int example[5]; // created on the stack
int* ptr = example;
example[0] = 33;
example[4] = 4;
for (int i = 0; i<5; i++){
example[i] = 2;
}
*(ptr + 2) = 6; // add 2*4 bytes because the pointer is int
//cout << example[0] << endl;
////cout << example << endl; // print adress, it is a pointer
for (auto i : example) {
cout << i << endl;
}
int* arr = new int[5]; // created on the heap, lifetime (if you return an array for example)
for (int i = 0; i<5; i++){
arr[i] = 2;
}
delete[] arr;
Entity e; // memory Entity accessing to the memory adress of ex (if int* ex)
int a[5];
int size = sizeof(a) / sizeof(int); // 5
return 0;
}