Skip to main content

4. Data types of c++

 • Data Types:- 

             While writing program in any language, you need to use various variables to store various information. Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. The following table shows the variable type, how much memory it takes to store the value in memory, and what is maximum and minimum value which can be stored in such type of variables.

• Types of Data types:-

1.Primary (fundamental) data types. 

2.Derived data types. 

3.User-defined data types

The following table shows the variable type, how much memory it takes to store the value in memory, and what is maximum and minimum value which can be stored in such type of variables.


Type Typical Bit Width Typical Range
char 1 bytes -127 to 127 or 0 to 255
unsigned char 1 bytes 0 to 255
signed char 1 bytes -127 to 127
int 4 bytes -2,147,483,648 to 2,147,483,647
unsigned int 4 bytes 0 to 4,294,967,295
signed int 4 bytes -2,147,483,648 to 2,147,483,647
short int 2 bytes -32,768 to 32,767
unshort int 2 bytes 0 to 65,535
signed short int 2 bytes -32,768 to 32,767
long int 8 bytes -(2^63) to (2^63)-1
signed long int 8 bytes same as long int
unsigned long int 8 bytes 0 to 18,446,744,073,709,551,615
float 4 bytes
double 8 bytes
long double 12 bytes


// C++ program to sizes of data types

#include<iostream>

using namespace std;

int main()

{

 cout << "Size of char : " << sizeof(char) << " byte" << endl;

 cout << "Size of int : " << sizeof(int) << " bytes" << endl;

 cout << "Size of short int : " << sizeof(short int) << " bytes" << endl;

 cout << "Size of long int : " << sizeof(long int) << " bytes" << endl;

 cout << "Size of signed long int : " << sizeof(signed long int) << " bytes" << endl;

 cout << "Size of unsigned long int : " << sizeof(unsigned int) << " bytes" << endl;

 cout << "Size of float : " << sizeof(float) << " bytes" <<endl;

 cout << "Size of double : " << sizeof(double) << " bytes" << endl;

 cout << "Size of wchar_t : " << sizeof(wchar_t) << " bytes" <<endl;


 return 0;

}


Output:-


Size of char : 1 byte

Size of int : 4 bytes

Size of short int : 2 bytes

Size of long int : 8 bytes

Size of signed long int : 8 bytes

Size of unsigned long int : 4 bytes

Size of float : 4 bytes

Size of double : 8 bytes

Size of wchar_t : 4 bytes


Comments

Popular posts from this blog

Remove specific item from Recyclerview in android studio

For Full video click on below link :- https://youtu.be/sUz4fqeanjI?si=A8AqBWCgu-5NnBOJ Working with the activity_main.xml file. Navigate to the   app > res > layout > activity_main.xml  and add the below code to that file. Below is the code for the   activity_main.xml   file.  <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical" android:background="@color/white"> <EditText android:layout_width="350dp" android:layout_height="50dp" android:inputType="text" android:id="@+id/coursenam...

Fingerprint Authentication in Android Studio Project

Implement the implementation : - implementation 'androidx.biometric:biometric:1.0.1' Working with the activity_main.xml file. Navigate to the   app > res > layout > activity_main.xml  and add the below code to that file. Below is the code for the   activity_main.xml   file. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" tools:context=".MainActivity" android:background="@color/white"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Welcome to the Boxcode!!" android:textSize=...

Sqlite with CRUD operation in Android studio

For Full video click on link :- https://youtu.be/QTvy8sJSiyI?si=dM1f98Mr7aFpJpqG Working with the activity_main.xml file. Navigate to the   app > res > layout > activity_main.xml  and add the below code to that file. Below is the code for the   activity_main.xml   file.  <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical" android:background="@color/white"> <EditText android:layout_width="350dp" android:layout_height="50dp" android:inputType="text" android:id="@+id/coursename...