Identifiers And Types

Identifiers in C++ can begin either with a letter, or with an underscore, while subsequent characters can be letters, underscores and digits. The following are valid identifiers:

i
_f
d1_
c2
Fp2
Identifiers must have a type. There are four built-in types which identify numerical values: int, float, double, char, corresponding respectively to integers, floating-point numbers, double precision floating-point numbers and characters. The size of each is implementation-dependent, but int is typically four bytes and char a byte. All types but char are signed by default. Whether char is signed or not is implementation-dependent. The int type can be modified by applying one of the following four modifiers:

unsigned
signed

short
long    
which make int, respectively, unsigned, signed, smaller (or unchanged) and bigger (or unchanged) in size. If one of the modifiers is used without an associated type, the type is by default int. So, for example: long longNumber; is equivalent to: long int longNumber; and: signed signedNumber; is equivalent to: signed int signedNumber;
long can also be applied to double, which usually translates in an increase in size. unsigned and signed can also be applied to char, which can be useful to make systems in which char is signed compatible with those in which it is not. See an example of different variable declarations below.

Example

 
#include <iostream>
using namespace std;

int main()
{   
     int i = 3.5;  // identifiers begin either with a letter
     float _f = 4; // or with an underscore
     double d1_;   // Subsequent characters can be letters, underscores or digits
     char c;

     // modified int
     unsigned int ui;
     signed int si;        // signed here makes no difference 

     short int shi;
     long int li;

     unsigned short int usi;
     signed short int ssi;  // signed here makes no difference

     unsigned long int uli;
     signed long int sli;  // signed here makes no difference

     // modified double
     long double ld;

     // modified char
     unsigned char uc;
     signed char sc;

     long longNumber; // is an int
     signed signedNumber; // is an int
}