-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProg.cpp
More file actions
36 lines (30 loc) · 1.16 KB
/
Copy pathProg.cpp
File metadata and controls
36 lines (30 loc) · 1.16 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
// Introducing sizeof OPERATOR.
// sizeof is a compile-time unary operator, not an execution-time function.
#include <iostream>
using namespace std;
size_t GetArray (int * , int);
// size_t is a type for storing sizes in bytes and for loop counter.
// size_t is normally unsigned int.
int main()
{
const int ArraySize = 5;
int a = 5;
unsigned int b = 5;
float c = 5;
double d = 5;
int Array1[ArraySize] = {1,2,3,4,5};
cout << "a : " << sizeof(a) <<"\nb : " << sizeof(b)
<< "\nc : " << sizeof(c) << "\nd : " << sizeof(d) << endl;
cout << "ArraySize : " << sizeof (ArraySize) << endl;
cout << "Array1 (with 5 integer elements) : " << sizeof (Array1) << endl;
cout << "Array1 has " << (sizeof Array1 / sizeof(int)) << " elements." << endl;
// When the operand of sizeof is a type name then it's necessary to use parantheses.
cout << "Gotten Array : " << GetArray(Array1,ArraySize) << endl;
return 0;
}
size_t GetArray (int *ArrayName , int ArraySize)
{
return sizeof ArrayName;
// It dosen't return the size of Array1 in main().
// It returns the size of ArrayName in current function which is a POINTER to an integer.
}