Di Posting Oleh : Simple Learning
Kategori : char in C++ float Variables and Data types in C++ programming
Variables
Definition
"Variable is a memory location in C++ Programming language"
Variable are used to store data on memory.
Why we use variables in C++ language?
Variables are used to store value and that values can be change.
The values of variables can be numeric or alphabet.
There are certain rules on choosing variable name:
Always declare variable in readable form e.g. name, sale etc.
Data type in C++ language
"A data type defines which kind of data will store in variables and also defines memory storage of data"
There are two kinds of data types User defined data types and Standard data types. In the beginning we will discuss only standard data types only.
In C++ language there are four main data types
If we chose char data type then we try to store an integer in it like then compiler will give an error if we put single quotes around 5 like that '5'.then compiler will store it as an character not integer.
ASCII VALUES OF CHARACTERS
Click on Image to view in large size
Integer data types
Integers are those values which has no decimal part they can be positive or negative. like 12 or -12.
There are 3 data types for integers
b) Unsigned int or unsigned short int
Signed int
The range of storing value of signed int variable is -32768 to 32767.It can interact with both positive and negative value.
Unsigned int
This type of integers cannot handle negative values. Its rang is 0 to 65535.
Long int
float 4 6 3.4E -38 to3.4E+38
double 8 15 1.7E - 308 to1.7E +308
long double 10 19 3.4E -4932 to 304E +4932
Definition
"Variable is a memory location in C++ Programming language"
Variable are used to store data on memory.
Why we use variables in C++ language?
Variables are used to store value and that values can be change.
The values of variables can be numeric or alphabet.
There are certain rules on choosing variable name:
- Variable name can consist of letter, alphabets and start with underscore character.
- First character of variable should always be alphabet and cannot be digit.
- Blank spaces are not allowed in variable name.
- Special characters like #, $ are not allowed.
- A single variable can only be declared for only 1 data type in a program.
- As C++ is case sensitive language so if we declare a variable name and one more NAME both are two different variables.
- C++ has certain keywords which cannot be used for variable name.
- A variable name can be consist of 31 characters only if we declare a variable more than 1 characters compiler will ignore after 31 characters.
Always declare variable in readable form e.g. name, sale etc.
Data type in C++ language
"A data type defines which kind of data will store in variables and also defines memory storage of data"
There are two kinds of data types User defined data types and Standard data types. In the beginning we will discuss only standard data types only.
In C++ language there are four main data types
- int
- float
- double
- char
- A keyword char is used for character data type.
- This data type is used to represents letters or symbols.
- A character variable occupies 1 byte on memory.
If we chose char data type then we try to store an integer in it like then compiler will give an error if we put single quotes around 5 like that '5'.then compiler will store it as an character not integer.
ASCII VALUES OF CHARACTERS
- There is an ASCII value for every character in C++ Language.
- On the basis of these ASCII values characters can be compare, subtract or add.
- Below chart is showing all the ASCII values of characters.
- Please do not confuse as your first look at table pay attention to only red characters and decimal values and ignore other values.
Click on Image to view in large size
Hex, Decimal, ASCII values C++ table |
Integer data types
Integers are those values which has no decimal part they can be positive or negative. like 12 or -12.
There are 3 data types for integers
- int
- short int
- long int
- int keyword is used for integers.
- It takes two bytes in memory.
- There are two more types of int data type
b) Unsigned int or unsigned short int
Signed int
The range of storing value of signed int variable is -32768 to 32767.It can interact with both positive and negative value.
Unsigned int
This type of integers cannot handle negative values. Its rang is 0 to 65535.
Long int
- As name refers it is used to represent larger integers.
- It takes 4byte in memory.
- The range of long int is -2147483648 to 2147483648.
- This type of integers contains fractional part.
- There are two further type of float integer's number.
- Number of bytes or memory taken by numbers
- Decimal places up to which they can represent value
- Range
float 4 6 3.4E -38 to3.4E+38
double 8 15 1.7E - 308 to1.7E +308
long double 10 19 3.4E -4932 to 304E +4932
0 Response to "Variables and Data Types in C++ programming"
Post a Comment