0% found this document useful (0 votes)
4 views3 pages

C++

Uploaded by

Sameeksha S
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)
4 views3 pages

C++

Uploaded by

Sameeksha S
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/ 3

DATATYPES

Data types can be categorized into three :-


1. Fundamental (Built-in) Data Types:
Fundamental data types are the basic or primitive data types provided by the programming language. They are
directly supported by the language and are used to represent simple values. These types are the building blocks
for defining variables and data structures.
Examples of fundamental data types in C++ include:
 Integers (e.g., int, short, long, long long)
 Floating-point numbers (e.g., float, double, long double)
 Characters (e.g., char, wchar_t)
 Boolean (e.g., bool)

2. Derived Data Types:


Derived data types are created by combining fundamental or other derived types to form new types. These types
are derived from fundamental data types and are used to represent complex entities. Derived types include
pointers, arrays, functions, and references.
Examples of derived data types in C++ include:
 Pointers (e.g., int*, char*)
 Arrays (e.g., int[], char[])
 References (e.g., int&, char&)
 Functions (e.g., function returning int, function taking double as argument)

3. User-Defined Data Types:


User-defined data types are created by the programmer based on the requirements of the program. These types
are defined using the fundamental and derived data types and can be customized to represent real-world entities
in a meaningful way. User-defined data types include structures, classes, unions, and enumerations.
Examples of user-defined data types in C++ include:
 Structures (struct): A collection of variables of different types grouped under a single name.
 Classes (class): A more advanced version of a structure, often used for object-oriented programming
(OOP), containing member variables and member functions.
 Unions (union): A data type that allows storing different data types in the same memory location, with
only one type active at a time.
 Enumerations (enum): A way to define a new data type with a set of named values.
In summary, fundamental data types are the basic building blocks, derived data types are created by combining
these basic types, and user-defined data types are defined by the programmer to organize and manipulate data in
a more structured and meaningful way.

1. Fundamental (Built-in) Data Types:


a. Integer Types:
 int: Integer data type.
 short: Short integer data type.
 long: Long integer data type.
 long long: Long long integer data type.

b. Floating-Point Types:
 float: Single-precision floating-point data type.
 double: Double-precision floating-point data type.
 long double: Extended precision floating-point data type.

c. Character Types:
 char: Character data type.
 wchar_t: Wide character data type.

d. Boolean Type:
 bool: Boolean data type, representing true or false.

2. Derived Data Types:

a. Array:
Collection of elements of the same data type accessed using an index.
b. Pointer:
Holds the memory address of another variable.
c. Reference:
Provides an alias to an existing variable.

3. User-Defined Data Types:

a. Struct:
Groups different data types under a single name.
b. Class:
Similar to a struct but can have member functions and access specifiers.
c. Union:
A special data type that can hold variables of different types but only one at a time.
d. Enumeration:
Allows you to define a type and specify the values it can take.
4. Void:
Represents the absence of a specific type.
#include <iostream>

int main() {
int age = 25;
float height = 5.9;
char grade = 'A';
bool isStudent = true;

std::cout << "Age: " << age << std::endl;


std::cout << "Height: " << height << std::endl;
std::cout << "Grade: " << grade << std::endl;
std::cout << "Is a student: " << std::boolalpha << isStudent << std::endl;

return 0;
}
In this example, we've used integer, float, character, and boolean data types to store information about a
person's age, height, grade, and student status, respectively.

You might also like