INTRODUCTION TO
C++ PROGRAMMING
• 1. What is C++?
• - C++ is a general-purpose programming language.
• - It was developed by Bjarne Stroustrup in the early 1980s.
• - C++ is an extension of the C language, adding object-oriented features.
• - It is used for system/software development, game programming, embedded
systems, and more.
• 2. Key Features of C++
• - Compiled language: Must be translated into machine code before
running.
• - Object-Oriented: Supports classes and objects.
• - Strongly typed: Variables must be declared with a type.
• - Fast and efficient.
3. Basic Structure of a C++ Program
#include <iostream> // Preprocessor directive
using namespace std; // Allows use of standard names
int main() { // Main function - entry point
cout << "Hello, World!"; // Output statement
return 0; // End of program
}
4. Explanation of Components
- #include <iostream> – Includes input/output stream library.
- using namespace std; – Allows the use of cout and cin without std:: prefix.
- int main() – Starting point of the program.
- cout – Used to display output on the screen.
- return 0; – Ends the program.
5. Writing and Running a C++ Program
- Use a text editor or an IDE (e.g., Code::Blocks, Dev-C++, Visual Studio).
- Save the file with a .cpp extension.
- Compile using a compiler (e.g., g++).
- Run the compiled executable file.
6. Common Errors to Avoid
- Missing semicolons ;.
- Misspelled keywords like main, return.
- Forgetting to include #include <iostream>.
7. First Task Example
*Write a C++ program that displays your name:*
#include <iostream>
using namespace std;
int main() {
cout << "My name is Charles Ghati";
return 0;
}