0% found this document useful (0 votes)
6 views2 pages

DATA TYPES IN C++LANGUAGE

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

DATA TYPES IN C++LANGUAGE

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

C++, data types are used to define the type of data that a variable can hold.

Each
data type has a specific size in memory and a range of values it can represent.
Data types are important for memory allocation, variable declaration, and
ensuring the correct manipulation of data. Here are some of the commonly used
data types in C++:
int: Integers are used to represent whole numbers. They can be either signed
(positive, negative, or zero) or unsigned (only positive or zero).
CPP CODE:
int x = 42;
float and double: Floating-point data types are used to represent real numbers
with a decimal point. float and double differ in precision.
CPP CODE:
float pi = 3.14; double e = 2.71828;
char: The char data type represents a single character. It can store characters like
letters, digits, and symbols.
CPP CODE:
char grade = 'A';
bool: The bool data type is used to represent boolean values, which can be either
true or false.
CPP CODE:
bool is Raining = true;
string: The string data type is not a built-in data type in C++ but is provided
through the Standard Template Library (STL). It is used to store sequences of
characters.
CPP CODE:
#include <string> std::string name = "John";
array: An array is a collection of elements of the same data type. It allows you to
store multiple values of the same type in a single variable.
CPP CODE:
int numbers[5] = {1, 2, 3, 4, 5};
struct: A struct is a user-defined data type used to group different data types
under a single name. It is often used to represent complex data structures.
CPP CODE:
struct Point { int x; int y; }; Point p1; p1.x = 10; p1.y = 20;
enum: An enumeration is a user-defined data type used to define a set of named
constant values. It's useful when you have a finite set of related values.
CPP CODE:
enum Color { Red, Green, Blue }; Color myColor = Red;
pointer: Pointers are used to store memory addresses of other variables. They
allow you to work with dynamic memory allocation and have more control over
memory.
CPP CODE:
int number = 42; int *ptr = &number; // ptr now holds the address of 'number'
user-defined data types: C++ allows you to define your own custom data types
using classes or structures. This is commonly used in object-oriented
programming to create objects with associated data and behavior.
CPP CODE:
class Student { public: int rollNumber; std::string name; }; Student student1;
student1.rollNumber = 101; student1.name = "Alice";

You might also like