Wednesday, June 26, 2013

C++ (beginner) variable types.how to declare a variable

This is the form of declaring a variable.
(variable type)  variable name;

There are a few variable types in C++.

char -  this is  s simple variable . It can only contain 1 character. It takes 1 byte space.
short int - this is a variable that can store a number. a number from  -32768 to 32767. It takes 2 bytes.
int - this variable is a number variable but its range is higher.  -2147483648 to 2147483647 . It takes 4 bytes
long - this can store a bigger number than the rpevious type.
long long - this can store even a bigger number than long type. it can store upto 2^64. (this variable ,as I mentioned above, long long a;   but it can also be declared __int64 a; 
double - this is a type which can store float numbers. ( double a;     or float a;)
bool - this is a basic boolean variable. It takes 1 bit memory and it has 2 possible values true or false. 

C++ is case sensitive. so int a and int A are different variables. If you write Int a (the first letter is uppercase ) you will sure get a compilation error.

There is a special key word called "unsigned". This can be written befor int,long,long long anf double. As the name suggests unsigned numbers are only the positive numbers. They can store from 0 to 2 times more than the original range of a certain type,

Example of a code

#include <iostream.h>
void main()
{
          int a;
         long b;
         long long c;
         double d;
         unsigned long e;
}



IF  YOU HAVE ANY QUESTIONS , LEAVE THEM IN COMMENTS, NO QUESTION WILL STAY UNANSWERED.

No comments:

Post a Comment