C++ Programming Tutorial
Learn modern C++ step-by-step with concise explanations and practical examples. Navigate topics from basics to advanced features using the sidebar.
Variables and Data Types
C++ has built-in types (`int`, `double`, `char`, `bool`) and standard types like `std::string`. Use `const` for values that should not change and `auto` to let the compiler infer types.
Declaring and Printing
#include \n#include \n\nint main() {\n int a = 10;\n double b = 3.14;\n char c = 'Z';\n bool ok = true;\n const std::string name = "Ada";\n auto ratio = b / a; // inferred double\n\n std::cout << a << " " << b << " " << c << " " << ok << " " << name << " " << ratio << std::endl;\n return 0;\n} Tips
- Prefer `std::string` over C-style strings for safety.
- Use `const` to prevent accidental modification.
- `auto` helps reduce verbosity but keep readability in mind.
Keep Practicing
Use the online compiler to run examples and test variations. Reinforce learning by building small programs for each topic.