Lesson 1 of 60 – Introduction to C++
2%

Introduction to C++

C++ is a powerful, general-purpose programming language used to create software, games, desktop applications, operating systems, embedded systems, and many other types of applications.

C++ is an extension of the C programming language and supports both procedural and object-oriented programming.

Note: C++ is pronounced as "C Plus Plus". It is one of the most widely used programming languages for learning programming concepts and building high-performance applications.

1. What is C++?

C++ is a general-purpose programming language developed as an extension of the C language. It provides features such as classes, objects, inheritance, polymorphism, and templates.

#include <iostream>

int main() {
    std::cout << "Hello World!";
    return 0;
}

The above program is a simple C++ program that displays a message.

2. Why Learn C++?

C++ is useful for learning important programming concepts.

  • It teaches programming fundamentals.
  • It supports object-oriented programming.
  • It provides high performance.
  • It is used in many real-world applications.
  • It helps build a strong programming foundation.

3. C++ is a General-Purpose Language

C++ is called a general-purpose language because it can be used to develop many different types of software.

  • Desktop applications
  • Games
  • System software
  • Embedded applications
  • High-performance applications

4. C++ and C

C++ was developed from the C programming language. Many basic concepts of C are also found in C++, but C++ adds several additional programming features.

For example, C++ supports classes and objects, which are fundamental concepts of object-oriented programming.

5. Object-Oriented Programming

C++ supports object-oriented programming, commonly called OOP. OOP organizes programs around objects and classes.

Important OOP concepts include:

  • Class
  • Object
  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction

6. C++ is a Compiled Language

C++ source code is normally compiled before it is executed. A compiler translates the source code into machine code that the computer can execute.

This compilation process helps C++ programs achieve high performance.

7. C++ Source Code

C++ source code is commonly saved using the .cpp file extension.

Example:

hello.cpp

The .cpp extension tells us that the file contains C++ source code.

8. First C++ Program

Here is a simple C++ program:

#include <iostream>

int main() {
    std::cout << "Welcome to C++";
    return 0;
}

This program displays Welcome to C++ on the screen.

9. The #include Directive

The #include directive is used to include a header file in a C++ program.

For example:

#include <iostream>

The iostream header provides functionality commonly used for input and output operations.

10. The iostream Header

The iostream header is commonly used when a C++ program needs standard input and output functionality.

It provides objects such as std::cout and std::cin.

#include <iostream>

11. The main() Function

The main() function is the entry point of a normal C++ program. Program execution begins from the main function.

int main() {
    return 0;
}

12. The int Return Type

In the following declaration, int specifies that the main function returns an integer value.

int main() {
    return 0;
}

The statement return 0; commonly indicates successful completion of the program.

13. Printing Output with std::cout

The std::cout object is used to display output on the standard output stream.

#include <iostream>

int main() {
    std::cout << "Hello C++";
    return 0;
}

14. The << Operator

The insertion operator << is commonly used with std::cout to send data to the output stream.

std::cout << "Hello";

Here, the text Hello is sent to the standard output.

15. Printing Multiple Values

You can use multiple insertion operators in the same statement.

std::cout << "Name: " << "Rahul";

This prints both pieces of text in sequence.

16. New Line in C++

The std::endl manipulator can be used to move the output to the next line.

std::cout << "Hello" << std::endl;
std::cout << "Welcome";

17. Using \n for a New Line

The escape sequence \n can also be used to create a new line.

std::cout << "Hello\n";
std::cout << "C++";

The second message will appear on the next line.

18. C++ Statements

A statement is an instruction that tells the program to perform an operation.

std::cout << "Hello";

Most C++ statements end with a semicolon ;.

19. Semicolon in C++

The semicolon is used to terminate many C++ statements.

int age = 20;
std::cout << age;

Forgetting a required semicolon can cause a compilation error.

20. C++ is Case-Sensitive

C++ is case-sensitive. This means uppercase and lowercase letters are treated differently.

int age = 20;
int Age = 30;

Here, age and Age are different identifiers.

21. Comments in C++

Comments are notes written inside source code. They are ignored by the compiler.

Single-line comment:

// This is a comment

Multi-line comment:

/*
   This is a
   multi-line comment
*/

22. C++ Variables

A variable is a named memory location used to store a value.

int age = 20;

Here, age is an integer variable containing the value 20.

23. Basic C++ Data Types

C++ provides several basic data types.

  • int – integer values
  • float – floating-point values
  • double – double-precision floating-point values
  • char – a character
  • bool – true or false
int age = 20;
double price = 99.50;
char grade = 'A';
bool passed = true;

24. Taking Input with std::cin

The std::cin object is commonly used to take input from the user.

#include <iostream>

int main() {
    int age;

    std::cin >> age;

    std::cout << "Age: " << age;

    return 0;
}

25. The >> Operator

The extraction operator >> is commonly used with std::cin to read input.

int number;

std::cin >> number;

26. Using std:: for Standard Library Names

Many names from the C++ standard library are available inside the std namespace.

std::cout << "Hello";
std::cin >> age;

The std:: prefix specifies that cout and cin belong to the standard namespace.

27. A Complete Simple Program

#include <iostream>

int main() {

    int age;

    std::cout << "Enter your age: ";
    std::cin >> age;

    std::cout << "Your age is: " << age;

    return 0;
}

This program takes an age from the user and displays it.

28. Where is C++ Used?

C++ is used in many areas of software development.

  • Game development
  • Operating systems
  • Desktop software
  • Embedded systems
  • Graphics applications
  • High-performance software

29. Advantages of C++

  • High performance
  • Supports object-oriented programming
  • Provides low-level programming capabilities
  • Supports generic programming through templates
  • Suitable for large and complex applications

30. What You Will Learn in This C++ Course

In this C++ tutorial series, you will gradually learn C++ from basic concepts to advanced programming topics.

  • C++ syntax and fundamentals
  • Variables and data types
  • Operators
  • Conditional statements
  • Loops
  • Functions
  • Arrays and strings
  • Pointers and references
  • Classes and objects
  • Inheritance and polymorphism
  • Templates
  • Exception handling
  • File handling
  • STL
  • Mini project

📌 Key Points

  • C++ is a general-purpose programming language.
  • C++ was developed as an extension of C.
  • C++ supports object-oriented programming.
  • The .cpp extension is commonly used for C++ source files.
  • The main() function is the entry point of a normal C++ program.
  • std::cout is used for output.
  • std::cin is used for input.
  • Most C++ statements end with a semicolon.
  • C++ is case-sensitive.

🧠 Quick Quiz

Question: Which language is C++ developed from?