Data Types

Data Types

C++ has several built-in data types that you can use to define variables and constants in your programs. Here are some of the most common data types in C++:

  1. Integer types:
  • int: a 32-bit signed integer.
  • short: a 16-bit signed integer.
  • long: a 32-bit or 64-bit signed integer.
  • long long: a 64-bit signed integer.
  1. Floating-point types:
  • float: a 32-bit floating-point number.
  • double: a 64-bit floating-point number.
  • long double: a larger floating-point number that can store more precision.
  1. Character types:
  • char: a 8-bit character.
  • wchar_t: a wide character, which can store characters from different character sets.
  • char16_t: a 16-bit character.
  • char32_t: a 32-bit character.
  1. Boolean type:
  • bool: a boolean value that can be either true or false.

Example:

				
					#include<iostream>

#include<string>

using namespace std;

int main() {

  int num = 10;

  float f = 3.14f;

  double d = 3.14159265359;

  bool is_true = true;

  char c = 'A';

  string name = "John Doe";

 cout << "Integer: " <<num << endl;

  cout << "Float: " << f<< endl;

  cout << "Double: " << d<< endl;

  cout << "Boolean: " <<is_true << endl;

  cout << "Character: "<< c << endl;

  return 0;

}
				
			
Join To Get Our Newsletter
Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *