Sobes.tech
Junior — Middle

Can you tell about different types of value-related data?

sobes.tech AI

Answer from AI

In C/C++, value types are data types that store data directly in the variable, rather than through a reference or pointer. These types include:

  • Primitive types: int, char, float, double, bool — store specific values.
  • Structures (struct) and unions (union): contain sets of values combined into a single object.
  • Enumerations (enum): a set of named integer constants.

When assigning or passing these types, the value itself is copied, not the reference to it. For example:

int a = 5;
int b = a; // b gets a copy of the value 5

struct Point {
    int x, y;
};

Point p1 = {1, 2};
Point p2 = p1; // copies the contents of p1 into p2

This differs from reference types (e.g., pointers), where the address is copied, not the data.