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

Input & Output In C++ (Basic)

Cout<<”Print sentence”;     This statement is use to print out any kinds of sentence or string type values. Cout<<345;     This statement is use to print out any kinds of numeric numbers, without change. Cout<<variable;        This statement is use to print the value of variable. The value of the which variable we want to print, It is need to write that variable on variable place.

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)