C++

By C-ore - January 11, 2021

 


What is C++

IT is a:
  • Multi-paradigm Language - C++ supports at least seven different styles of programming. Developers can choose any of the styles.
  • General Purpose Language - You can use C++ to develop games, desktop apps, operating systems, and so on.
  • Speed - Like C programming, the performance of optimized C++ code is exceptional.
  • Object-oriented - C++ allows you to divide complex problems into smaller sets by using objects.

Why Learn C++?

  • C++ is used to develop games, desktop apps, operating systems, browsers, and so on because of its performance.
  • After learning C++, it will be much easier to learn other programming languages like Java, Python, etc.
  • C++ helps you to understand the internal architecture of a computer, how computer stores and retrieves information.

Basic Syntax

C++ "Hello World!" Program

// Your First C++ Program

#include <iostream>

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

Print Number Entered by User

#include <iostream>
using namespace std;

int main()
{    
    int number;

    cout << "Enter an integer: ";
    cin >> number;

    cout << "You entered " << number;    
    return 0;
}

Swap Numbers (Using Temporary Variable)

#include <iostream>
using namespace std;

int main()
{
    int a = 5, b = 10, temp;

    cout << "Before swapping." << endl;
    cout << "a = " << a << ", b = " << b << endl;

    temp = a;
    a = b;
    b = temp;

    cout << "\nAfter swapping." << endl;
    cout << "a = " << a << ", b = " << b << endl;

    return 0;
}

  • Share:

You Might Also Like

0 comments