DATA
TYPE
|
SIZE
(IN BYTES)
|
RANGE
|
short int
|
2
|
-32,768 to 32,767
|
unsigned short int
|
2
|
0 to 65,535
|
unsigned int
|
4
|
0 to 4,294,967,295
|
int
|
4
|
-2,147,483,648 to
2,147,483,647
|
long int
|
4
|
-2,147,483,648 to
2,147,483,647
|
unsigned long int
|
4
|
0 to 4,294,967,295
|
long long int
|
8
|
-(2^63) to (2^63)-1
|
unsigned long long int
|
8
|
0 to
18,446,744,073,709,551,615
|
signed char
|
1
|
-128 to 127
|
unsigned char
|
1
|
0 to 255
|
float
|
4
|
|
double
|
8
|
|
long double
|
12
|
|
wchar_t
|
2 or 4
|
1 wide character
|
Encapsulation is an Object Oriented Programming
concept that binds together the data and functions that manipulate the
data, and that keeps both safe from outside interference and misuse.
Data encapsulation led to the important OOP concept of data hiding.
Data encapsulation is
a mechanism of bundling the data, and the functions that use them and data
abstraction is a mechanism of exposing only the interfaces and hiding
the implementation details from the user.
Data Encapsulation
Example
Any
C++ program where you implement a class with public and private members is an
example of data encapsulation and data abstraction. Consider the following
example −
#include
<iostream>
using
namespace std;
class
Adder {
public:
// constructor
Adder(int i = 0) {
total = i;
}
// interface to outside world
void addNum(int number) {
total += number;
}
// interface to outside world
int getTotal() {
return total;
};
private:
// hidden data from outside world
int total;
};
int
main() {
Adder a;
a.addNum(10);
a.addNum(20);
a.addNum(30);
cout << "Total " <<
a.getTotal() <<endl;
return 0;
}
When the above code is
compiled and executed, it produces the following result – 60
Above class adds numbers together, and returns
the sum. The public members addNum and getTotal are the interfaces to the outside world and a user needs to
know them to use the class. The private member total is something that is hidden from the outside world, but
is needed for the class to operate properly.
Nice post. Test comment
ReplyDelete