C++ Data Types
C++ supports a wide variety of data types, which are divided into two main categories: primitive types and user-defined types. Primitive types are those that are built into the language, such as int, float, and char. User-defined types are those that are created by the programmer, such as classes and structs.
Let’s look at an example of declaring and using variables in C++:
#include <iostream>
int main()
{
int x = 10;
float y = 20.5;
char z = 'a';
std::cout << "x = " << x << std::endl;
std::cout << "y = " << y << std::endl;
std::cout << "z = " << z << std::endl;
return 0;
}
Output
Output:
x = 10
y = 20.5
z = a
In this example, we have declared three variables: an integer (x), a float (y), and a character (z). We have also used the cout stream to print out the values of these variables.