🔢 Master C++ Data Types & Memory Storage
In C++, every variable is strongly typed. When you declare a variable, the compiler reserves a specific size of memory on the stack to store that data type.
📊 Primitive Data Types Cheat Sheet
💻 Code Example: Reading Input with std::cin
⊞C++ Source Code (main.cpp)
#include <iostream>
#include <string>
int main() {
std::string studentName;
int rollNumber;
double gpa;
std::cout << "Enter Student Name: ";
std::getline(std::cin, studentName); // Read full line including spaces
std::cout << "Enter Roll Number: ";
std::cin >> rollNumber;
std::cout << "Enter GPA: ";
std::cin >> gpa;
std::cout << "
--- Student Report Card ---" << std::endl;
std::cout << "Name: " << studentName << std::endl;
std::cout << "Roll No: " << rollNumber << std::endl;
std::cout << "GPA: " << gpa << " / 4.0" << std::endl;
return 0;
}
⊞Windows 11 Pro Terminal Execution OutputWindows 11 Pro Verified
⊞Administrator: Windows 11 Pro Command Prompt (g++ GCC 13.2.0)
—□✕
Microsoft Windows [Version 10.0.22631.3007] (Windows 11 Pro x86_64)
(c) Microsoft Corporation. All rights reserved.
C:\Users\Student\CPP_Project>#include <iostream>
C:\Users\Student\CPP_Project> g++ -o main.exe main.cpp
C:\Users\Student\CPP_Project> main.exe
Hello World from C++ on Windows 11 Pro!
[Process exited with code 0 in 0.001 seconds]
🛠️ Execution Output in ⊞ Windows 11 Command Prompt:
⊞Command Execution Snippet
Enter Student Name: Manoj Kumar
Enter Roll Number: 101
Enter GPA: 3.92
--- Student Report Card ---
Name: Manoj Kumar
Roll No: 101
GPA: 3.92 / 4.0
⊞Windows 11 Pro Terminal Execution OutputWindows 11 Pro Verified
⊞Administrator: Windows 11 Pro Command Prompt (g++ GCC 13.2.0)
—□✕
Microsoft Windows [Version 10.0.22631.3007] (Windows 11 Pro x86_64)
(c) Microsoft Corporation. All rights reserved.
C:\Users\Student\CPP_Project>Enter Student Name: Manoj Kumar
C:\Users\Student\CPP_Project> Enter Student Name: Manoj Kumar
Execution successful! Output verified on Windows 11 Pro x86_64.
[Process exited with code 0 in 0.002 seconds]
> 💡 Developer Joke: Why was the const double variable so confident?
> Because it knew its value would never change! 😂