Explain Data Types in C++

Explain Data Types in C++
Explain Data Types in C++

C++ Data Types: A Data type can store the value. Every variable in C++ has an initialize data type. It is specified the type of data that the variable can store like integer data type(int), character data type(char) , floating data type(float) and double data type etc.

C++ language is a statically type where every variable's data type must be specified at the declaration and once specified. It is a type of data which is used in the C++ program. A data types specifies the type of data stored in a variable.
There are two types of data type.
  • Basic Data Types
  • Derived

Basic Data Types in C++

Data TypeDescriptionSize (bytes)Format Specifier
intInteger can stores whole numbers without decimals.2 or 4%d or %i
floatfloat can stores only floating-point numbers.4%lf
charchar can stores only a single character value.1%c
doubledouble can stores double-precision floating-point numbers.8%lf
voidvoid represents the absence of a value do not return a value.0N/A


Derived Data Types in C++

Array Data Type: Array is a collection of elements of the same data type stored contiguous memory location in a same single name.

Pointer Data Type: Pointer is a special type variable. It can store only address of another variable. Pointer denoted by (*) symbols.

Function Data Type: Function is a name of block of code that perform an specific task and small number of block.

Boolean Data Type: The bool data type in C++ is used to represent logical values, which can either be true or false. It is commonly used in conditional statements and to represent the result of logical
expressions. Boolean can be stores logical values, with two possible values true (1)
and false (0).

User Defined Data Types in C++

Structure(struct): Structure is a group of multiple variable of different data types in a single name.
Union(union): Union allows multiple variables to share the same memory location. But union can store only one value at a time.
Enumeration(enum): Enum is a symbolic name with integer constants.
Typedef: Typedef can be used alias or new name for existing data type name.

Type of Data Types in C++

Basic Data TypeDerived Data Type
Integer Type(int)Pointer
Floating Type(float)Array
Character Type(char)Structure
N/AUnion

Integer Data Types in C++

Data TypeSize in bytesRange
short2-32768 to +32767
int2-32768 to +32767
unsigned int20 to 65536
long4-2147483648 to +2147483647
unsigned long int40 to 4,294,967,295

Example of Integer Data Types in C++

#include<iostream>
using namespace std;
int main(){
int x=100;
cout<<"Value of x:"<<x;
}
============OUTPUT============
Value of x:100


Float Data Types in C++

Data TypeSize in bytesRange
float43.4E-38 to 3.4E+38
double81.7E-308 to 1.7E+308
Long double103.4E-4932 to 1.1E+4932

Example of Float Data Types in C++

#include<iostream>
using namespace std;
int main(){
float marks=76.8;
cout<<"Value of Marks:"<<marks;
}
============OUTPUT============
Value of Marks:76.8


Character Data Types in C++

Data TypeSize in bytesRange
char1-128 to +127
signed char1-128 to +127
unsigned char10 to 255

Example of Character Data Types in C++

#include<iostream>
using namespace std;
int main(){
char grade='J';
cout<<"Value of Grade:"<<grade;
}
============OUTPUT============
Value of Grade: J


Example Size Find Data Types in C++

#include<iostream>
using namespace std;
int main(){
cout<<"Size of Integer Data:"<<sizeof(int)<<endl;
cout<<"Size of Float Data:"<<sizeof(float)<<endl;
cout<<"Size of Character Data:"<<sizeof(char)<<endl;
cout<<"Size of Double Data:"<<sizeof(double)<<endl;
}
============OUTPUT============
Size of Integer Data:4
Size of Float Data:4
Size of Character Data:1
Size of Double Data:8


Conclusion of Data Types in C++

Conclusion: Data Types is a most important part of C++ language. It is a overview all data types. I can explain briefly define in the next topic simple and easy language. so you can support my content and suggestion any doubt you can email and comments.

Post a Comment

0 Comments