মূল কন্টেন্টে যান
eLearner.app
মডিউল 1 · 1-এর পাঠ 3কোর্সে 1/18~10 min
মডিউল পাঠ (1/3)

ভেরিয়েবল এবং ডেটা প্রকার

In C++, every variable has a well-defined static type at compile time. This means that once you declare a variable of a certain type, you cannot change its type later.

This approach guarantees maximum performance at runtime and allows the compiler to catch many common errors before the program even runs.

Declaration and Initialization

To declare a variable in C++, you must specify the type first, followed by the name of the variable:

Code
int age; // Declaration without initialization (contains an undefined value!)
age = 25; // Subsequent assignment

Modern Initialization

Modern C++ introduces several forms of initialization. The safest and most uniform is brace initialization (introduced in C++11):

Code
int age = 25;       // Classic initialization (C-style)
int score {100};    // Uniform initialization (C++11)

Fundamental Primitive Types

Here are the main data types you will use every day:

TypeDescriptionExample
intInteger numbers (e.g. 1, -42, 0)int points = 50;
doubleDouble-precision floating-point numbersdouble price = 19.99;
charA single character enclosed in single quoteschar grade = 'A';
boolBoolean values (true or false)bool isActive = true;

Complex Objects: std::string

To manage text sequences, the C++ standard library provides the std::string class (defined in the <string> header):

Code
#include <string>

std::string name = "Alice";

Try it yourself

ব্যায়াম#cpp.m1.l1.e1
প্রচেষ্টা: 0লোড হচ্ছে...

Declare a variable named age of type int with value 30, and print it using std::cout.

সম্পাদক লোড হচ্ছে...
ইঙ্গিত দেখান

Use the syntax `int age = 30;`to declare the variable, then print it with`std::cout << age;`.

সমাধান 3 প্রচেষ্টার পরে উপলব্ধ

ব্যায়াম#cpp.m1.l1.e2
প্রচেষ্টা: 0লোড হচ্ছে...

Declare a variable named username of type std::string with value 'Alice', and print it using std::cout.

সম্পাদক লোড হচ্ছে...
ইঙ্গিত দেখান

Usa `std::string username = "Alice";` e poi inviala allo stream std::cout.

সমাধান 3 প্রচেষ্টার পরে উপলব্ধ