🟢 Foundation  ·  Lesson 07

Variables and Data Types in C++

Variables and Data Types in C++

What is Variables and Data Types in C++?

Variables and Data Types in C++
A variable is a named memory location used to store data. Data type tells the compiler what kind of value will be stored and how much memory may be needed.
Level
🟢 Beginner – C++ Foundation
Example File
variables-data-types.cpp
Main Focus
Concept + syntax + practical C++ program

Why should you learn this?

  • It helps you write correct and readable C++ programs.
  • It is used repeatedly in school practicals, projects and competitive programming.
  • It builds the base for advanced topics such as OOP, STL and data structures.

Important Terms

TermMeaning / Use
intVariables and Data Types in C++ programming में Int use होता है।
floatVariables and Data Types in C++ programming में Float use होता है।
doubleVariables and Data Types in C++ programming में Double use होता है।
charVariables and Data Types in C++ programming में Char use होता है।
boolVariables and Data Types in C++ programming में Bool use होता है।
stringVariables and Data Types in C++ programming में String use होता है।

Syntax / Pattern

C++
data_type variable_name = value;

Example Program

main.cpp
#include <iostream>
using namespace std;

int main() {
    int age = 16;
    double percentage = 92.5;
    char grade = 'A';
    bool passed = true;

    cout << age << " " << percentage << " " << grade << " " << passed;
    return 0;
}

Expected Output

16 92.5 A 1

Program Explanation

  • bool true is printed as 1 by default.
  • double stores decimal values with better precision than float.
  • char stores a single character.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.

Where will you use it?

  • student records
  • fee calculation
  • marks and percentage
  • conditions

Common Mistakes

  • Using int for decimal values.
  • Using single quotes for full strings.
  • Using invalid variable names with spaces.

Practice Tasks

  1. Create variables for roll number, name, marks and grade.
  2. Print size of different data types using sizeof().

Summary

Variables and Data Types in C++ एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।

Variables and Data Types in C++ क्या है?

Variables and Data Types in C++
A variable is a named memory location used to store data. Data type tells the compiler what kind of value will be stored and how much memory may be needed.
Level
🟢 Beginner – C++ Foundation
Example File
variables-data-types.cpp
मुख्य फोकस
Concept + syntax + practical C++ program

इसे क्यों सीखें?

  • यह आपको सही और पढ़ने-योग्य C++ programs लिखने में मदद करता है।
  • यह school practicals, projects और competitive programming में बार-बार use होता है।
  • यह OOP, STL और data structures जैसे advanced topics की नींव बनाता है।

ज़रूरी Terms

Termअर्थ / उपयोग
intInt Variables and Data Types in C++ programming में use होता है।
floatFloat Variables and Data Types in C++ programming में use होता है।
doubleDouble Variables and Data Types in C++ programming में use होता है।
charChar Variables and Data Types in C++ programming में use होता है।
boolBool Variables and Data Types in C++ programming में use होता है।
stringString Variables and Data Types in C++ programming में use होता है।

Syntax / Pattern

C++
data_type variable_name = value;

Example Program

main.cpp
#include <iostream>
using namespace std;

int main() {
    int age = 16;
    double percentage = 92.5;
    char grade = 'A';
    bool passed = true;

    cout << age << " " << percentage << " " << grade << " " << passed;
    return 0;
}

Expected Output

16 92.5 A 1

Program Explanation

  • bool true is printed as 1 by default.
  • double stores decimal values with better precision than float.
  • char stores a single character.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.

Where will you use it?

  • student records
  • fee calculation
  • marks and percentage
  • conditions

आम गलतियाँ (Common Mistakes)

  • Using int for decimal values.
  • Using single quotes for full strings.
  • Using invalid variable names with spaces.

अभ्यास (Practice Tasks)

  1. Create variables for roll number, name, marks and grade.
  2. Print size of different data types using sizeof().

सारांश

Variables and Data Types in C++ एक ज़रूरी C++ topic है। परिभाषा सीखें, syntax समझें, example program चलाएं और फिर practice tasks हल करके concept मज़बूत करें।

← Back to C++ Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n

💻 Live Code Editor

Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें. Agar load na ho to naye tab mein kholें.