C++ Programming Basics Lesson 1
C++ Programming Basics Lesson 1
Introduction to C++
C++ is a general-purpose programming language created by Bjarne Stroustrup. It is widely used in
system/software development and game development.
C++ is an extension of the C language and includes object-oriented, generic, and functional
features.
In this lesson, we'll start with the basics: creating a simple program, understanding variables, and
learning about data types.
#include <iostream>
using namespace std;
int main() {
cout << "Hello, world!" << endl;
return 0;
}
- #include <iostream> includes the input-output stream library to allow us to use 'cout' for displaying
text.
- using namespace std; lets us avoid writing 'std::' before every standard command.
- int main() is the entry point of any C++ program. The code inside this function runs when we
execute the program.
Variables
Variables are used to store data in C++. A variable has a name, a type, and a value.
To declare a variable, specify its type, followed by the variable name, and (optionally) assign a
value.
Examples:
int age = 25; // Declares an integer variable named age with value 25
float height = 5.9; // Declares a floating-point variable named height
char grade = 'A'; // Declares a character variable named grade
string name = "John"; // Declares a string variable named name
Exercise
1. Write a simple C++ program to declare variables of different types (int, float, char, string, bool)
and display them using cout.
2. Try changing the values of these variables and observing the output to see how they work in
different contexts.