Data Types in C++

Data type specify the type of data that can be save in variable. Each variable must have data type. Data type limit specific set of values for variables to store. C++ provides the following data types.

List of Data Types used in C++

No Data Type Size in Bytes Description
1 char 1 It is used to store single character. This may be Alphabet/Number or Symbol.
2 bool 1 it is used to store true/false.
3 int 4 It is used to store numbers without decimal digits
4 float 4 It is used to store small floating point values.
5 double 8 It is used to store large floating point values.

1. char

Char data type stores single character or ASCII value. This character may be Alphabet or Number. It takes one bytes in memory.

Example of char data type

#include <iostream>
using namespace std;

int main(int argc, char** argv) {
	char grade;
	grade = 'A';
	cout<<grade;
	
	return 0;
}

2. bool

Bool data type only store two values either true of false. True or False are keyword in C++.

Example of bool data type

#include <iostream>
using namespace std;

int main(int argc, char** argv) {
	bool a;
	a=false;
	if(a) {
	     cout<<"Checked";
	}
	return 0;
}

3. int

int data type is used to store natural numbers without decimal point. It is most commonly used data type. It is also used in itterative structure as counter variable.

Example of int data type

#include <iostream>
using namespace std;

int main(int argc, char** argv) {
      int a;
      a = 100;
      cout<<a;
	
      return 0;
}

4. float

float data type takes 4 bytes in memory location. It is used to store small decimal values.

Example of float data type

#include <iostream>
using namespace std;

int main(int argc, char** argv) {
      float temp;
      temp = 97.8;
      cout<<temp;
	
      return 0;
}

5. double

double data type is used to store large decimal values. It takes 8 bytes in memory.

Example of double data type

#include <iostream>
using namespace std;

int main(int argc, char** argv) {
      double distance;
      distance = 975465476584343.8903;
      cout<<distance;
	
      return 0;
}

 

Comments
Login to TRACK of Comments.