Skip to main content

Variables And Data Types In C++


Name
Size*
Range*
Example
Char
1 byte
Signed: -128 to 127
unsigned: 0 to 255
‘a’,’b’,’c’
Int
4 byte
Signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
123,456,73,1.
Bool
1byte
True or false
True,false
Float
4bytes
+/- 3.4e +/- 38 (~7 digits)
132.23,2.5,7
Double
8bytes
+/- 1.7e +/- 308 (~15 digits)
1647464364,567

Char
Char type of variable are use to assign or store a character which is enclose by 2 single quotes
char ch='k';   //ch contain 1 character  
Char b[]=”programming is fun.”; 
P
R
O
G
R
A
M
M
I
N
G

I
S

F
U
N
.
/0

In the sentence of “programming is fun.” Has 19 character include space. If we store this sentence in a char type array , we need to declare an array with 20 element.

Int
Int is use to define numeric variable holding whole number. The size of number that can be stored within -2,147,483,648 to 2,147,483,647 in 32 bit.
Bool
A Boolean constant is used to check the state of a variable, an expression, or a function, as true or false. To declare such a value, you use the bool keyword. The variable can then be initialized with the starting value. 
Float
Float is used to define numbers with fractional parts. It can represent the values of ranging from approximately 1.5 × 10−45 to 3.4 × 1038 with a precision of 7 digits

Double
A double is a larger float type that holds both bigger and more precise numbers.
Double variables are 8 bytes in size. The range of values is from 2.2250738585072020×10−308 to 1.7976931348623157×10308
More importantly, the precision of a double is 15 compared to 6 for a float. The precision of a number is how many digits (before and after the decimal point) it can store without errors occurring.







Comments

Popular posts from this blog

Switch, Case, Default Statements In C++

Switch case is uses as alternative of if….else. When we need to use long term of if…else then we use switch case for reducing program execution time. syntax: Switch(variable){ Case value 1: Statement; Break; Case value 2: Statement; Break;

do...while loop in C++

The do while loop is very similar to while loop . In the while loop first check final condition then execute the statement. But in the do while loop first execute the statement then check the final condition. Syntax: Initialization; Do{ increment/decrement;   } while(Final condition)

For Loop In C++

A loop can repeat the statement of a particular job continuously for a specific number of times. Loop Description Syntax For The condition can tested before statement execution.   For(Initialization, Final condition, increment /decrements ) { statement; } while First it check the condition then do the job. Initialization; While(Final condition) { Statement; increment /decrements; } Do..while First do job then test the condition. Initialization; Do{ Statement; increment /decrements; } While(Final condition)