C++ Programming में दो प्रकार के Data Types होते है |
- Basic Data Types
- Derived Data Types
| Basic Data Types | Derived Data Types |
|---|---|
|
|
Basic Data Types
1. int (Integer)- Integer Data Type में variable को declare करने के 'int' keyword का इस्तेमाल करते है |
- Integer Data Type सभी numeric values को store कर सकता है |
- Integer Data Type 2, 4 और 8 bytes के हो सकते है |
- अगर Computer का Processor 16-bit हो तो int का size 2 Bytes होता है |
- अगर Computer का Processor 32-bit हो तो int का size 4 Bytes होता है |
- अगर Computer का Processor 64-bit हो तो int का size 8 Bytes होता है |
Integer Data Types, Storage Size and Range
| Data Types | Storage Size | Range |
|---|---|---|
| int (16-bit) | 2 Bytes | -32,768 to 32,767 |
| int (32-bit) | 4 Bytes | -2,147,483,648 to 2,147,483,647 |
| int (64-bit) | 8 Bytes | -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807 |
| unsigned int (16-bit) | 2 Bytes | 0 to 65,535 |
| short int | 2 Bytes | -32,768 to 32,767 |
| unsigned short int | 2 Bytes | 0 to 65,535 |
| signed short int | 2 Bytes | –32,768 to 32,767 |
| long int | 4 Bytes | –2,147,483,647 to 2,147,483,647 |
| unsigned long int | 4 Bytes | 0 to 4,294,967,295 |
| signed long int | 4 Bytes | –2,147,483,648 to 2,147,483,647 |
sizeof इस keyword से int Data Types के size का पता करे |
Source Code :
#include <iostream.h>
using namespace std;
int main() {
cout<<"int(16-bit) storage size: "<<sizeof(int)<<endl;
cout<<"int(32-bit) storage size: "<<sizeof(int)<<endl;
cout<<"int(64-bit) storage size: "<<sizeof(int)<<endl;
cout<<"unsigned int storage size: "<<sizeof(unsigned int)<<endl;
cout<<"short int storage size: "<<sizeof(short int)<<endl;
cout<<"unsigned short int storage size: "<<sizeof(unsigned short int)<<endl;
cout<<"signed short int storage size: "<<sizeof(signed short int)<<endl;
cout<<"long int storage size: "<<sizeof(long int)<<endl;
cout<<"unsigned long int storage size: "<<sizeof(unsigned long int)<<endl;
cout<<"signed long int storage size: "<<sizeof(signed long int)<<endl;
return 0;
}
Outputint(16-bit) storage size: 2 int(32-bit) storage size: 4 int(64-bit) storage size: 8 unsigned int storage size: 4 short int storage size: 2 unsigned short int storage size: 2 signed short int storage size: 2 long int storage size: 4 unsigned long int storage size: 4 signed long int storage size: 4
2. char (Character)
- Character Data Type में variable को declare करने के 'char' keyword का इस्तेमाल करते है |
- सिर्फ एक ही character को declare कर सकते है | for eg. 'H'
- अगर multiple character मतलब पूरे एक string को print करना हो तो double quotes("") का इस्तेमाल करते है | for eg. char arr[10] = "Hello";
- Character Data Type 1 byte का होता है |
for eg.
#include <iostream.h>
using namespace std;
int main() {
char str1='H'; // declare varible in single quotes
//char str2[10]='Hello'; // Get Warning Error
char str3[10]="Hello";
cout<<"Single quoted Print Character : "<<str1<<endl;
//cout<<"Single quoted Print String : "<<str2<<endl; //Get Warning Error
cout<<"Double quoted Print Character : "<<str3<<endl;
return 0;
}
Note : ऊपरवाला Program Warning
Error देगा | User single quotes और double quotes के बिच का फर्क जानने के
लिए ऊपरवाला Program दिया है |
OutputSingle quoted Print Character : H Double quoted Print Character : Hello
Character Data Types, Storage Size and Range
| Data Types | Storage Size | Range |
|---|---|---|
| char | 1 Byte | -128 to 127 |
| unsigned char (16-bit) | 1 Byte | 0 to 255 |
| signed char | 1 Byte | --128 to 127 |
sizeof इस keyword से char Data Types के size का पता करे |
Source Code :
#include <iostream.h>
using namespace std;
int main(){
cout<<"char storage size : "<<sizeof(char)<<endl;
cout<<"unsigned char storage size : "<<sizeof(unsigned char)<<endl;
cout<<"signed char storage size : "<<sizeof(signed char)<<endl;
return 0;
}
Outputchar storage size : 1 unsigned char storage size : 1 signed char storage size : 1
3. float (Floating-point)
- Floating-point Data Type में variable को declare करने के 'float' keyword का इस्तेमाल करते है |
- Floating-pont Data Type 4 bytes का होता है | |
for eg.
#include <iostream.h>
using namespace std;
int main() {
float a=5, b=3.145;
cout<<"Value of Float variable : "<<a<<endl;
cout<<"Value of b : "<<b<<endl;
return 0;
}
OutputValue of Float variable : 5 Value of b : 3.145000
Floating-point Data Type, Storage Size and Range
| Data Types | Storage Size | Range | Digits of Precision |
|---|---|---|---|
| float | 4 Bytes | 1.2E-38 to 3.4E+38 | 6 |
sizeof इस keyword से char Data Types के size का पता करे |
Source Code :
#include <iostream.h>
using namespace std;
int main() {
cout<<"Floating-point Storage size : "<<sizeof(float);
return 0;
}
OutputFloating-point Storage size : 4
4. double
- Double Data Type में variable को declare करने के 'double' keyword का इस्तेमाल करते है |
- Double Data Type 8 bytes का होता है | |
- Double और Floating-point Data Type में कोई फर्क नहीं है |
for eg.
#include <iostream.h>
using namespace std;
int main() {
double a=5.45;
cout<<"Value of Double variable : "<<a;
return 0;
}
OutputValue of Double variable : 5.45
Double Data Types, Storage Size and Range
| Data Types | Storage Size | Range | Digits of Precision |
|---|---|---|---|
| double | 8 Bytes | 2.3E-308 to 1.7E+308 | 15 |
| long double | 10 Bytes | 3.4E-4932 to 1.1E+4932 | 19 |
sizeof इस keyword से char Data Types के size का पता करे |
Source Code :
#include <iostream.h>
using namespace std;
int main() {
cout<<"Double Storage size : "<<sizeof(double);
return 0;
}
OutputDouble Storage size : 8
5. void
- void मतलब null value |
- void में कोई value नहीं होती |
- ये data type function और function के parameter / argument के लिए इस्तेमाल करते है |
- ये कोई value return नहीं करता |
for eg.
#include <iostream.h>
using namespace std;
void hello(void); // function with no return value and parameter
main()
{
hello();
}
void hello(void)
{
cout<<"Hello World";
}
OutputHello World
6. bool(Boolean)
- Boolean के लिए सिर्फ दो constant values होती है |
- अगर true होता है, तो 1 return किया जाता है और false होता है, तो 0 return किया जाता है |
for eg.
#include <iostream.h>
using namespace std;
int main(){
bool value = true;
cout<<"value : "<<value<<endl;
value = false;
cout<<"Changed value is "<<value;
return 0;
}
Outputvalue : 1 Changed value is 0
7. wchar_t(Wide character)
- wchar_t ये wide characters होते है |
- ये data type 2 bytes या 4 bytes का होता है |
- wchar_t ये Unicode के लिए इस्तेमाल किया जाता है |
for eg.
#include <iostream.h>
using namespace std;
int main(){
wchar_t str[] = L"Hello";;
wcout << "Wide character value : "<<str<<endl; //wcout is used for wide stream(Unicode)
cout << "Size of the wide char : " <<sizeof(wchar_t); //cout is used for standard stream(Unicode)
return 0;
}
OutputWide character value : Hello Size of the wide char : 2







No comments: