• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Basics of C++ For Beginners

By Abhishek Ghosh May 9, 2024 11:18 am Updated on May 9, 2024

Basics of C++ For Beginners

Advertisement

C++ is an ISO-standardized programming language. It was developed in 1979 by Bjarne Stroustrup at AT&T as an extension of the C programming language. C++ enables efficient and machine-oriented programming as well as programming at a high level of abstraction. The standard also defines a standard library for which different implementations exist.

 

Features of C++

 

C++ is used in both system programming and application programming and is one of the most widely used programming languages in both. Typical applications in system programming include operating systems, embedded systems, virtual machines, drivers, and signal processors. C++ often takes the place that used to be reserved exclusively for assembly languages and the C programming language. In application programming, C++ is mainly used where high demands are placed on efficiency to make the best possible use of performance limits imposed by technical framework conditions. Beginning in 2000, C++ was pushed back from the domain of application programming by the Java and C# languages.

The C++ language uses only about 95 keywords, some of which are used multiple times in different contexts. Similar to the C language, it gets its actual functionality from the C++ standard library, which teaches the language missing important functionalities (arrays, vectors, lists, …) as well as establishes the connection to the operating system (iostream, fopen, exit, …). Depending on the area of application, additional libraries and frameworks are added. C++ focuses on the language tools used to develop libraries. As a result, it favours generalised mechanisms for typical problems and has hardly any individual solutions integrated into the language.

Advertisement

---

One of the strengths of C++ is the ability to combine efficient, machine-oriented programming with powerful language tools that summarize simple to complex implementation details and largely hide them behind abstract sequences of commands. Template metaprogramming comes into play here: a technique that allows an almost uncompromising combination of efficiency and abstraction. However, some design decisions are also often criticized.

C++ does not have garbage collection, but there are efforts to enable garbage collection through libraries or by including it in the language standard. It is possible to use C’s memory management (malloc/realloc/free); to implement low-level functions in libraries such as the C++ standard library, this is necessary to access C library functions. However, this is strongly discouraged in general C++ code. Instead, it is common practice to let the standard C++ library take care of memory management by using the container classes offered. The C++ Standard Library provides:

  • Containers (container classes)
  • Iterators
  • Algorithms
  • Function Objects
  • Strings
  • Input and Output
  • Localization
  • Numerics
  • Exceptions
  • RTTI (Runtime Type Information)
  • Random Number Generators and Transformers
  • Tools for multithreading
  • Regular expressions
  • Timekeeping tools

Most of the components of the C++ standard library are in the form of template classes. This concept has the great advantage of reusability, for example, containers for arbitrary data types can be created by simple declaration; Algorithms apply to a wide range of data types. Furthermore, templates ensure type safety during compilation, which minimizes runtime errors. One disadvantage is the extremely difficult-to-read error messages that are generated, for example, in the event of type conflicts.

You’ll find the list of all the keywords here:

Vim
1
https://en.cppreference.com/w/cpp/keyword

 

How to Compile C++ Program and Run

 

The easiest way to write code in C++, compile and run (for self-study & learning process) is to use the Unix/Linux Terminal. In the case of Microsoft Windows, you can use Ubuntu Bash (WSL 2).

You need to have C++, g++, and Nano installed, probably all of them are already installed:

Vim
1
2
3
c++ --version
g++ --version
nano --version

Open nano:

Vim
1
nano hello.cpp

Copy and paste the below example and save the file (ctrl+O):

Vim
1
2
3
4
5
6
#include <iostream>
 
int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Next, compile it:

Vim
1
g++ -o hello hello.cpp

Next, execute it:

Vim
1
./hello

You’ll get the output “Hello, World!”.

Basics of C++ For Beginners

Of course, later you can use an IDE, such as Microsoft Visual Studio.

 

How to Write Program in C++

 

Hello World Program

Let’s begin with the classic “Hello, World!” program, which is often the first program written by beginners in any programming language:

Vim
1
2
3
4
5
6
#include <iostream>
 
int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

In this program:

#include : This line includes the input/output stream library, which provides functionality for input and output operations.
int main(): Every C++ program must have a main() function, which serves as the entry point of the program.
std::cout << "Hello, World!" << std::endl;: This line outputs the "Hello, World!" message to the standard output (usually the console).
return 0;: This statement indicates that the program executed successfully and returns an exit status of 0.

Variables and Data Types

C++ supports various data types to represent different kinds of values, such as integers, floating-point numbers, characters, and more. Here's an example of declaring variables and using different data types:

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
 
int main() {
    // Integer variable
    int num = 42;
 
    // Floating-point variable
    float pi = 3.14;
 
    // Character variable
    char letter = 'A';
 
    // Output variables
    std::cout << "Integer: " << num << std::endl;
    std::cout << "Float: " << pi << std::endl;
    std::cout << "Character: " << letter << std::endl;
 
    return 0;
}

Control Flow Statements

C++ provides various control flow statements, such as if-else, for, while, and switch, to control the flow of program execution. Here's an example using if-else and for loops:

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
 
int main() {
    int num = 10;
 
    // If-else statement
    if (num > 0) {
        std::cout << "Positive" << std::endl;
    } else {
        std::cout << "Non-positive" << std::endl;
    }
 
    // For loop
    for (int i = 0; i < 5; ++i) {
        std::cout << "Iteration " << i + 1 << std::endl;
    }
 
    return 0;
}

Functions

Functions in C++ are reusable blocks of code that perform specific tasks. Here's an example of defining and calling a function to calculate the factorial of a number:

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
 
// Function to calculate factorial
int factorial(int n) {
    if (n == 0 || n == 1) {
        return 1;
    }
    return n * factorial(n - 1);
}
 
int main() {
    int num = 5;
 
    // Call factorial function
    int result = factorial(num);
 
    // Output result
    std::cout << "Factorial of " << num << " is " << result << std::endl;
 
    return 0;
}

Basic Calculator

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
 
using namespace std;
 
int main() {
    char op;
    float num1, num2;
 
    // Display menu and prompt for operator choice
    cout << "Enter operator (+, -, *, /): ";
    cin >> op;
 
    // Prompt for two numbers
    cout << "Enter two numbers: ";
    cin >> num1 >> num2;
 
    // Perform operation based on operator choice
    switch (op) {
        case '+':
            cout << "Result: " << num1 << " + " << num2 << " = " << num1 + num2;
            break;
        case '-':
            cout << "Result: " << num1 << " - " << num2 << " = " << num1 - num2;
            break;
        case '*':
            cout << "Result: " << num1 << " * " << num2 << " = " << num1 * num2;
            break;
        case '/':
            // Check for division by zero
            if (num2 != 0)
                cout << "Result: " << num1 << " / " << num2 << " = " << num1 / num2;
            else
                cout << "Error! Division by zero!";
            break;
        default:
            // Display error for invalid operator
            cout << "Error! Invalid operator.";
            break;
    }
 
    return 0;
}

You'll get these examples from my GitHub repository too. Do not forget to follow me on GitHub.

 

Conclusion

 

This article provides a glimpse into the basics of C++ programming, covering essential concepts such as variables, data types, control flow statements, and functions, with illustrative code examples. As you continue your journey in learning C++, remember to practice regularly, explore more advanced topics, and build projects to solidify your understanding. With dedication and perseverance, you'll soon become proficient in C++ and unlock endless possibilities in software development.

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Basics of C++ For Beginners

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • WordPress & PHP : Different AdSense Units on Mobile Devices

    Here is How To Serve Different AdSense Units on Mobile Devices on WordPress With PHP. WordPress Has Function Which Can Be Used In Free Way.

  • Dictionary of DLL, VXD, OCX files

    In this tutorial we are offering a small dictionary of the DLL, VXD, OCX and related to so they can see what each of them belongs.

  • PHP Snippet to Hide AdSense Unit on WordPress 404 Page

    Here is Easy PHP Snippet to Hide AdSense Unit on WordPress 404 Page to Avoid Policy Violation and Decrease False Impression, False Low CTR.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

vpsdime

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Cloud-Powered Play: How Streaming Tech is Reshaping Online GamesSeptember 3, 2025
  • How to Use Transcribed Texts for MarketingAugust 14, 2025
  • nRF7002 DK vs ESP32 – A Technical Comparison for Wireless IoT DesignJune 18, 2025
  • Principles of Non-Invasive Blood Glucose Measurement By Near Infrared (NIR)June 11, 2025
  • Continuous Non-Invasive Blood Glucose Measurements: Present Situation (May 2025)May 23, 2025
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2026 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy