Data Types of C++ Language (C++ भाषा के डाटा टाइप)

A data type specifies the type of value that a variable can store, along with its storage requirements and permitted operations.

C++ provides several data types, including Built-in Data Types, Derived Data Types, and User-Defined Data Types, to store and manipulate different kinds of values.

डाटा टाइप यह निर्धारित करता है कि किसी वेरिएबल में किस प्रकार का मान संग्रहित किया जा सकता है तथा उस मान पर कौन-कौन से ऑपरेशन किए जा सकते हैं।

C++ भाषा में विभिन्न प्रकार के मानों को संग्रहित एवं उपयोग करने के लिए Built-in Data Types, Derived Data Types तथा User-Defined Data Types का प्रयोग किया जाता है।

Classification of Data Types (डाटा टाइप का वर्गीकरण)

C++ language data types can be classified into the following three categories:

C++ भाषा के डाटा टाइप को निम्नलिखित तीन श्रेणियों में वर्गीकृत किया जा सकता है:

  1. Built-in Data Types (बिल्ट-इन डाटा टाइप)

  2. Derived Data Types (डीराइव्ड डाटा टाइप)

  3. User-Defined Data Types (यूजर-डिफाइंड डाटा टाइप)

1) Built-in / Fundamental Data Types (बिल्ट-इन / फंडामेंटल डाटा टाइप)

Built-in data types are the fundamental data types provided by the C++ language. They are used to store basic values such as integers, characters, floating-point numbers, and Boolean values.

C++ भाषा द्वारा प्रदान किए गए मूलभूत डाटा टाइप को Built-in या Fundamental Data Types कहा जाता है। इनका प्रयोग पूर्णांक, अक्षर, दशमलव संख्याएँ तथा Boolean मान संग्रहित करने के लिए किया जाता है।

Some important built-in data types are:

Data TypeDescription
intStores integer values
charStores character values
floatStores single-precision floating-point values
doubleStores double-precision floating-point values
boolStores true or false values
voidRepresents no value or no return type

Example

#include <iostream>
using namespace std;
int main()
{
int age = 25;
char grade = 'A';
float marks = 85.5;
double salary = 25000.75;
bool result = true;
cout << age << endl;
cout << grade << endl;
cout << marks << endl;
cout << salary << endl;
cout << result << endl;
return 0;
}

Explanation (English)

In this example, different variables are declared using different built-in data types. Each variable stores a value of its respective type.

व्याख्या (हिन्दी)

इस उदाहरण में विभिन्न Built-in Data Types की सहायता से वेरिएबल बनाए गए हैं। प्रत्येक वेरिएबल अपने निर्धारित डाटा टाइप के अनुसार मान संग्रहित करता है।

Note about void

The void type represents the absence of a value. It is commonly used to specify that a function does not return a value.

void किसी मान की अनुपस्थिति को दर्शाता है। इसका प्रयोग सामान्यतः ऐसे फंक्शन के लिए किया जाता है जो कोई मान वापस नहीं लौटाते हैं।

Example:

void display()
{
cout << "Hello C++";
}

A variable cannot be declared with void as its ordinary object type.

सामान्य वेरिएबल को void डाटा टाइप के साथ घोषित नहीं किया जा सकता।

2) Derived Data Types (डीराइव्ड डाटा टाइप)

Derived data types are created or derived from fundamental data types. They are used to represent more complex data and operations.

मूलभूत डाटा टाइप की सहायता से बनाए जाने वाले डाटा टाइप को Derived Data Types कहा जाता है। इनका प्रयोग जटिल डाटा तथा ऑपरेशन को दर्शाने के लिए किया जाता है।

Some important derived data types are:

  • Array

  • Pointer

  • Function

  • Reference

Example

int a = 10;
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = &a;
int &ref = a;

Explanation (English)

  • An array stores multiple values of the same data type.

  • A pointer stores the memory address of another object.

  • A function performs a particular task.

  • A reference provides another name for an existing object.

व्याख्या (हिन्दी)

  • Array एक ही डाटा टाइप के अनेक मानों को संग्रहित करता है।

  • Pointer किसी अन्य ऑब्जेक्ट का Memory Address संग्रहित करता है।

  • Function किसी विशेष कार्य को पूरा करता है।

  • Reference किसी पहले से मौजूद ऑब्जेक्ट का दूसरा नाम प्रदान करता है।

3) User-Defined Data Types (यूजर-डिफाइंड डाटा टाइप)

User-defined data types are created by programmers according to the requirements of a program.

प्रोग्राम की आवश्यकता के अनुसार प्रोग्रामर द्वारा बनाए गए डाटा टाइप को User-Defined Data Types कहा जाता है।

Some important user-defined data types are:

  • Structure (struct)

  • Union (union)

  • Class (class)

  • Enumeration (enum)

Structure (स्ट्रक्चर)

A structure is used to group related variables of different data types under a single name.

Structure का प्रयोग विभिन्न डाटा टाइप के संबंधित वेरिएबल्स को एक ही नाम के अंतर्गत समूहित करने के लिए किया जाता है।

Example:

struct student
{
int rollno;
char name[20];
float marks;
};

Union (यूनियन)

A union is used to define different members that share the same memory location.

Union में विभिन्न Members एक ही Memory Location को साझा करते हैं।

Example:

union data
{
int i;
float f;
char ch;
};

Enumeration (एनुमरेशन)

An enumeration is a user-defined data type that consists of named integral constants.

Enumeration एक User-Defined Data Type है जिसमें नामयुक्त Integer Constants को परिभाषित किया जाता है।

Example:

enum day
{
MON, TUE, WED, THU, FRI, SAT, SUN
};

Class (क्लास)

A class is a user-defined type that combines data members and member functions into a single unit. It is used to represent objects or entities in real-world applications.

Class एक User-Defined Type है जो Data Members तथा Member Functions को एक इकाई में संगठित करती है। इसका प्रयोग वास्तविक दुनिया की वस्तुओं या Entities को प्रोग्राम में दर्शाने के लिए किया जाता है।

A class is declared using the class keyword.

Class को class Keyword की सहायता से घोषित किया जाता है।

Syntax

class class_name
{
private:
// Data members and member functions
protected:
// Data members and member functions
public:
// Data members and member functions
};

Example

class employee
{
private:
int empid;
char empname[20];
float salary;
public:
void getemp();
void setemp();
};

Explanation (English)

  • class is the keyword used to declare a class.

  • employee is the class name.

  • empid, empname, and salary are data members.

  • getemp() and setemp() are member functions.

  • private, protected, and public are access specifiers.

  • Class members are private by default.

व्याख्या (हिन्दी)

  • class क्लास घोषित करने के लिए उपयोग किया जाने वाला Keyword है।

  • employee क्लास का नाम है।

  • empid, empname तथा salary Data Members हैं।

  • getemp() तथा setemp() Member Functions हैं।

  • private, protected तथा public Access Specifiers हैं।

  • Class के Members डिफॉल्ट रूप से Private होते हैं।

Creating an Object of a Class (क्लास का ऑब्जेक्ट बनाना)

An object is an instance of a class. Objects are created using the class name.

Object किसी Class का Instance होता है। Object बनाने के लिए Class के नाम का प्रयोग किया जाता है।

Example:

employee e1, e2;

Here, e1 and e2 are objects of the employee class.

यहाँ e1 तथा e2, employee Class के Objects हैं।

C++ data types are used to define the kind of values a program can store and process. Built-in data types store basic values, derived data types are formed from existing types, and user-defined data types allow programmers to create their own data structures.

C++ Data Types यह निर्धारित करते हैं कि प्रोग्राम किस प्रकार के मानों को संग्रहित एवं प्रोसेस कर सकता है। Built-in Data Types मूलभूत मानों को संग्रहित करते हैं, Derived Data Types मूलभूत डाटा टाइप से बनाए जाते हैं तथा User-Defined Data Types प्रोग्रामर को अपने स्वयं के Data Types बनाने की सुविधा प्रदान करते हैं।

Comments

Popular posts from this blog

Important Questions (IMP) of Programming Methodologies and Data structures using C++ with OOP's Concepts

Programming Methodologies and Data structures using C++ Language with OOP's Concepts

OOP's using CPP Syllabus AND Programming Methodologies and Data Structures Using C++ (NEP 2020)