Syntax | Name | use |
---|---|---|
char | character | Character or very short integer (-128..127) |
short | short integer | uses 2 byte memory, value between -32768 and 32767 |
int | ordinary integer | uses 4 byte memory, value between -2147483648 and 2147483647 |
long | long integer | uses 8 bytes memory, value between -9223372036854775808 and 9223372036854775807 |
float | single precision float | uses 4 byte memory, absolute value between 1.4E-45 and 3.4E38 |
double | double precision float | uses 8 byte memory, absolute value between 4.9E-324 and 1.8E308 |
bool | boolean | true (1) or false (0) |
float A, B, C; - Defines 3 float variables A = 4; B = 5; C = A + B; |
int A; - Defines integer float B, C; - Defines 2 float variables A = 4; // Integer B = 5; // Float C = A + B; - value of A is converted to FLOAT first !!! |
|
Warning:
(C++ is designed for system programming; and system programmers prefer to have access to all features of the computer. Compiler checks often limit the programmers' ability to perform some tasks. Hence, C++ compilers are less strongly typed than Java) |
Example:
int i; short s; i = 9827563; s = i; // <-- This conversion is allowed in C++ // without casting !!! |
class CLASSNAME { variable definitions function (method) definitions } |
Example:
class my_int { int value; // Member variable }; |
The similarity is quite deceiving; because the underlying representation of objects is completely different
However, we need to delay this and study the fundaments of C++ first.
We will look at this much later...