C++: DataTypes

Some good references  :

 
 

Primitive data types (in built)

Name Description Size Range
char Character or small integer. 1byte signed: -128 to 127
unsigned: 0 to 255
short int (short) Short Integer. 2bytes signed: -32768 to 32767
unsigned: 0 to 65535
int Integer. 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
long int (long) Long integer. 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
bool true or false. 1byte true or false
float Floating point number. (unsigned can't be used ) 4bytes 3.4e +/- 38 (7 digits)
double Double precision floating point number.
(unsigned can't be used )
8bytes 1.7e +/- 308 (15 digits)
long double Long double precision floating point number. 8bytes 1.7e +/- 308 (15 digits)
wchar_t Wide character. 2bytes 1 wide character
 

Data Type-Modifiers

The three data types, namely  int, double and float as shown above have the following modifiers.
  • short : defined as short int n1;
  • long : long int n2 ;
  • signed
  • unsigned
 
 
 
User Defined Types
struct or class  sum of size of each member
  • Default access modifier for struct for members  is public.
  • Default access modifier for classes is private.
  • Data-Type is a compound type.
union size of the largest member
  • Default access modifier for for members is public.
  • Data-Type is a compound type.
enum size of char
  • Enumerations are a distinct type from ints. ints are not implicitly converted to enums, unlike in C. Also ++/-- cannot be applied to enum's unless overloaded.
typedef same as the type being given a name
  • typedef has syntax similar to a storage class like static, register or extern.
template  size of char

 

 
Working with Derived Types ( class, struct, and union)
type&
(reference) using addressof
int a1 = 12;
int x1= null;
// & operator
x1 = &a1;
type* (pointer) void func(int *n1)
type [integer]
(array)
int a1[10];
int *x1= a1;
// indexed
x1[0] = 12;
type (comma-delimited list of types/declarations)
(function)
int a1[5]= {1,2,3,4};
void proxy(float(*)(int,double),int, double)
type aggregate_type::*
(member pointer)
void(Base::*aBase)(int, double)=&Base::setdata;

 
 
Escape Sequence Represents
\a Bell (alert)
\b Backspace
\f Formfeed
\n New line
\r Carriage return
\t Horizontal tab
\v Vertical tab
\' Single quotation mark
\" Double quotation mark
\\ Backslash
\? Literal question mark
\ooo ASCII character in octal notation
\xhhh ASCII character in hexadecimal notation