Friday, 2 January 2026

Day 2: Anatomy of Data | Variables & Data Types in C++

📅 Date: Jan 2, 2026
🔥 Topic: Variables, Primitives & Data Types


📦 What are Variables?

Yesterday, I printed static text. But software needs to handle changing data. That's where Variables come in.

Think of a variable as a container or a box in the computer's memory where we store data. Every box needs two things:

  • A Name: To identify it (e.g., age, score).
  • A Type: To tell the computer what kind of data is inside (Number? Text? Decimal?).

🗂️ Data Types in C++

C++ is a "strongly typed" language. This means if I create a box for an integer, I cannot force text into it. Here are the fundamental types I learned today:

  • int: Stores whole numbers (e.g., 25, -10).
  • float / double: Stores decimal numbers (e.g., 9.8, 3.14). Double is just a more precise float.
  • char: Stores a single character in single quotes (e.g., 'A', '$').
  • string: Stores text in double quotes (e.g., "Sahil"). (Requires #include <string>)
  • bool: Stores logical values: true (1) or false (0).

💻 Day 2 Code: Creating a User Profile

To practice this, I wrote a program that stores different types of data for a user profile and prints them out.

#include <iostream>
using namespace std;

int main() {
    // 1. Integer (Whole Number)
    int age = 19;
    
    // 2. Float (Decimal)
    float cgpa = 8.5;
    
    // 3. Character (Single Letter)
    char grade = 'A';
    
    // 4. Boolean (True/False)
    bool isCoder = true;
    
    // 5. String (Text)
    string name = "Sahil";

    // Displaying the Data
    cout << "--- ID CARD ---" << endl;
    cout << "Name: " << name << endl;
    cout << "Age: " << age << endl;
    cout << "CGPA: " << cgpa << endl;
    cout << "Grade: " << grade << endl;
    
    // Bool prints 1 for true, 0 for false
    cout << "Is Coder? " << isCoder << endl;

    return 0;
}

🧠 Key Takeaway: Memory Size

I also learned that different types take up different amounts of space in memory (RAM).

  • int usually takes 4 bytes.
  • char takes only 1 byte.
  • double takes 8 bytes.

We can check this using the sizeof() function!


💭 Thoughts

Variables make code dynamic. Instead of hardcoding "Sahil", I can now store it in a variable `name` and change it whenever I want. Tomorrow, I plan to look into If/Else Conditionals to make decisions in code.

Thursday, 1 January 2026

Day 1: Hello World, Inputs & The C++ Boilerplate

📅 Date: Jan 1, 2026
🔥 Topic: C++ Basics, Boilerplate, Input/Output


🚀 What is C++?

Today, I started my journey with C++. It is one of the most powerful, high-performance programming languages used for everything from Game Development to System Programming. It's a compiled language, meaning the code is translated into machine code before running, making it super fast.


🛠️ The Boilerplate (The Skeleton)

Every C++ program needs a basic structure to run. This is called the Boilerplate. Without this, the compiler won't know where to start.

#include <iostream> // 1. Header File
using namespace std;    // 2. Standard Namespace

int main() {            // 3. Main Function (Entry Point)
    
    // Code goes here...
    
    return 0;           // 4. Exit Status
}
Breakdown:
1. #include <iostream>: Brings in input/output functionality.
2. using namespace std;: Helps us use standard commands like 'cout' directly.
3. int main(): This is where the execution begins.
4. return 0;: Tells the OS that the program ended successfully.

💻 How to Print Output (cout)

To display something on the screen, we use cout (Character Output) combined with insertion operators <<.

cout << "Hello World!" << endl;

Note: endl is used to move to a new line.


⌨️ How to Take User Input (cin)

To take data from the user, we use cin (Character Input) with extraction operators >>.

int age;
cin >> age;

⚡ Day 1: Full Code Snippet

Putting it all together, here is the first program I wrote today. It takes the user's name and goal, then prints it back.

#include <iostream>
using namespace std;

int main() {
    // Variable Declaration
    string name;
    int goalYear;

    // Output
    cout << "Enter your name: ";
    // Input
    cin >> name;

    cout << "Enter your target year: ";
    cin >> goalYear;

    // Final Output
    cout << "-------------------------" << endl;
    cout << "User: " << name << endl;
    cout << "Mission Deadline: " << goalYear << endl;
    cout << "Let's grind!" << endl;

    return 0;
}

💭 Thoughts

The logic is similar to other languages, but C++ feels much more closer to the hardware. Understanding cin and cout is just the start. Tomorrow, I will dive into Variables and Data Types in depth.

Day 2: Anatomy of Data | Variables & Data Types in C++

📅 Date: Jan 2, 2026 🔥 Topic: Variables, Primitives & Data Types 📦 What are Variables? Yesterda...