type of variable c++ code example

Example 1: c++ variable type

// Example
std::cout << "Data-type = " << typeid(YourVariable).name() << "\n";
  
// Syntax
typeid(YourVariable).name()

Example 2: print data type of a variable in c++

int x = 5;
typeid(x).name();
//output: i
// i stands for int

Example 3: c++ declare variable

std::string str = "text";	// stores a string
int    foo = 3;				// stores any integer
float  bar = 3.14;			// stores 32 bit number
double baz = 3.14159265;	// stores 64 bit number

Example 4: define type c++

typedef unsigned int u_int; //giving 'unsigned int' a name of u_int

Tags:

Cpp Example