-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathArrayDecay.cpp
More file actions
53 lines (39 loc) · 1.4 KB
/
ArrayDecay.cpp
File metadata and controls
53 lines (39 loc) · 1.4 KB
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
// =====================================================================================
// ArrayDecay.cpp // Array Decay
// =====================================================================================
module modern_cpp:array_decay;
namespace ArrayDecay {
static void displayValue(int* p) {
std::cout << "New size of array by passing the value : ";
std::cout << sizeof(p) << std::endl;
}
static void displayPointer(int(*p)[10]) {
std::cout << "New size of array by passing the pointer : ";
std::cout << sizeof(p) << std::endl;
}
const int n = 10;
static void displayReference(int(&p)[n]) {
std::cout << "New size of array by passing reference: ";
p[5] = 99;
std::cout << sizeof(p) << std::endl;
}
static void test_01 () {
int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::cout << "Actual size of array is : ";
std::cout << sizeof(arr) << std::endl;
displayValue(arr);
displayPointer(&arr);
displayReference(arr);
for (int elem : arr) {
std::cout << elem << ' ';
}
}
}
void main_array_decay()
{
using namespace ArrayDecay;
test_01();
}
// =====================================================================================
// End-of-File
// =====================================================================================