C++ Data Types

C++ supports several data types, including primitive types and user-defined types. Here are some of the most common data types in C++:

Primitive Types:

  • Integers: "int", "short", "long", "long long", "unsigned int", "unsigned short", "unsigned long", and "unsigned long long".
  • Floating-point numbers: "float", "double", and "long double".
  • Characters: "char".
  • Booleans: "bool".

User-defined Types:

  • Arrays: a collection of elements of the same type.
  • Structures: a collection of elements of different types.
  • Classes: similar to structures, but with additional features such as encapsulation, inheritance, and polymorphism.
  • Enumerations: a set of named integer constants.

Here is an example of how to declare variables of different data types in C++:

int age = 42;
double salary = 50000.0;
char grade = 'A';
bool isMarried = true;

In this example, we declare variables of different data types: an integer named "age", a double named "salary", a character named "grade", and a boolean named "isMarried".

C++ also provides operators and functions for working with different data types, such as arithmetic operators for numerical types, and string functions for working with strings. Understanding the different data types and how to work with them is an important part of writing effective C++ code.

Comments

Leave a Reply

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

82630