- C++ Course Basics
- C++ Tutorial
- C++ Basic Syntax
- C++ Identifiers
- C++ Character Set
- C++ Input/Output Operator
- C++ Variables
- C++ Data Types
- C++ Formatting Output
- C++ Operators
- C++ Assignment Operator
- C++ Type Conversion
- C++ Program Control
- C++ if and if-else
- C++ switch
- C++ loops
- C++ break and continue
- C++ Functions
- C++ Functions
- C++ Prototype and Definition
- C++ Function Call
- C++ Function Types
- C++ Friend Function
- C++ Function Overloading
- C++ Arrays and Strings
- C++ Arrays
- C++ One-Dimensional Arrays
- C++ Strings
- C++ String Functions
- C++ Structures
- C++ Structures
- C++ Nested Structure
- C++ Structure Array
- C++ Pass Structure to Function
- C++ Pointers
- C++ Pointers
- C++ Memory Map
- C++ Declare Initialize Pointers
- C++ Pointers and Structures
- C++ Object-Oriented
- C++ Object-Oriented
- C++ Classes and Objects
- C++ Constructors and Destructors
- C++ Objects as Function Arguments
- C++ Pointers and Objects
- C++ Data Structure
- C++ Linked List
- C++ Stack
- C++ Queues
- C++ File Handling
- C++ File Handling
- C++ Opening and Closing Files
- C++ Steps to Process Files
- C++ Sequential I/O Operations
- C++ Detecting EOF
- C++ File Pointers Random Access
- C++ Binary Files Operations
- C++ Error Handling
- C++ Misc
- C++ typedef
- C++ #define
- C++ Date and Time
- C++ Examples
- C++ Examples
C++ Tutorial
Hi, my name is William. I'm here to teach you one of the most well-known and prestigious computer programming languages in the most efficient manner possible, utilizing both brief and essential theory as well as practical codes and their outputs.
However, I believe there are a few questions we should answer before beginning the course. So, let's start right away by answering some important questions about the programming language "C++."
What is C++?
C++ is a general-purpose computer programming language that has the following primary characteristics:
- object-oriented
- dynamic memory allocation
- generic
- functional
C++ is a C programming language extension. C++ contains all of the elements of the C language as well as extra features for working with objects, classes, events, and other object-oriented concepts.
C++ influenced many computer programming languages, of which the following is a list of some of the most famous and powerful ones:
- Java
- Python
- PHP
including C#, Perl, and many more.
Who Invented C++? | A Quick History
Bjarne Stroustrup created the C++ programming language in 1980 at AT&T Bell Laboratories. He discovered that "C" was lacking in simulations (the technique of representing the real world by a computer program) and decided to extend the language by incorporating some features from Simula 67, his favorite language.
Simula 67 was one of the first object-oriented programming languages. Bjarne Stroustrup originally referred to it as "C with Classes."
Rick Mascitti coined the term "C++." The "++" operator is an increment operator in C++. C++ has evolved to deal with problems encountered by users and through discussions at AT&T since its inception.
The C++ programming language first appeared in 1985. Can you imagine the age of this language?
Because of its age, the language is now very stable, and there is a large community to help you if you start coding in C++ and get stuck somewhere.
The main reason for C++'s success
The main reason why C++ is so successful and well-known is that it uses object-oriented technology, which is the newest and most realistic way to make software.
A brief message for our students
C++'s official website is isocpp.org. If you are only conversant with C++. I mean, if you're a die-hard C++ developer who relies solely on this language, I recommend you keep visiting the official website. As a result, you will receive all announcements regarding news, updates, and much more.
Almost every computer language now has its own official website, not just C++; for example, "HTML" has "html.spec.whatwg.org," "Python" has "python.org," "Java" has "oracle.com/java/java.com," and so on. However, most people, especially beginners, find it difficult to learn the language from the official site; thus, we step in to select the main topics and briefly explain them so that even a beginner learner can grasp the concept.
C++ Environment Setup
I recommend that we start by preparing the environment. So please allow me to assist you in configuring a C++ environment for your system so that you can easily execute C++ code.
I won't recommend installing a code editor like Notepad++ or "Visual Studio Code" and then separately installing the "compiler" for you. Instead, I recommend that you download and install one of the well-known free, open-source, cross-platform IDEs that includes a compiler (GNU GCC Compiler).
So simply search for "CodeBlocks download" and open any relevant page to download and install it. In my case, here's a screenshot of the download window. I included this screenshot for your convenience. This image depicts the approximate download size of a "Code::Blocks IDE."
Install the "Code::Blocks IDE" on your system after downloading it. This is one of the windows you will see while installing. I included this screenshot to demonstrate the space size required by this IDE.
After installing "Code::Blocks," launch it. Now, as shown by the red arrow in the following screenshot, click on "Create a new project."
Then, as shown in the screenshot below, click on "Files."
Now select "C/C++ source" and press the "Go" button as shown below:
Now another window may appear, in which you must select "Next," and the following windows will appear:
Select "C++" and then click the "Next" button. Now, click the three dots as shown below, navigate to the folder, type the file name "codescracker.cpp," and then click the "Finish" button. The ".cpp" extension indicates that the file contains C++ source code.
Following the completion of the preceding steps, you will see the following window:
Now enter your C++ source code in the above-mentioned box. As an example:
That is, I have written the following C++ program:
#include<iostream> using namespace std; int main() { cout<<"Welcome!"; cout<<endl; return 0; }
To see the output of the above C++ source code, navigate to "Build" and select "Build and run" or directly hit the "F9" key. After building and running the above C++ program, here is a snapshot of the output:
I used the red arrow to focus your attention solely on the output text.
In a separate article, I defined each and every line of code in the preceding C++ example program. You can find it here: C++ basic syntax.
Now that everything is in place, let's get started on the course.
Comments in C++
Comments are content written within the program to explain specific blocks of code or to aid in debugging.
Comments are text that is ignored by the compiler during compilation and execution in C++ or any other programming language. The two types of comments that can be used in a C++ program are as follows:
Single-line comments in C++
Comments that span only one line are known as "single-line comments." Anything written after "//" is referred to as the content of the single-line comment. For example:
// C++ program to print "codescracker" on output console. #include<iostream> using namespace std; int main() { cout<<"codescracker"; // cout<<"codescracker"; cout<<endl; return 0; }
The above C++ example programme will produce the following output:
codescracker
In the above example, the second "cout" statement will not be executed because I used "//" to make it a comment.
Multi-line comments in C++
Comments that span multiple lines are known as "multi-line comments." Anything written between "/*" and "*/" is referred to as a multi-line comment. For example:
#include<iostream>
using namespace std;
int main()
{
/* The following statement
* will print the text
* "codescracker"
* on the output console
*/
cout<<"codescracker";
cout<<endl;
return 0;
}
You will get the same output as in the previous example. You can also use "/* comment_content */" to write a single-line comment.
Hot C++ programming language topics
The following is a list of hot C++ programming language topics that will be covered in separate posts.
- Basic syntax of a C++ program
- What are C++ variables?
- Data types in C++
- List of operators with descriptions and examples in C++
- if...else if...else statements in C++ with examples
- switch case in C++
- Loops in C++ programming
- break and continue statements in C++
- Functions in C++
- Arrays in C++
- Strings in C++
- Structures in C++
- Pointers in C++
- Object-oriented programming with C++
- Classes and objects in C++
- Linked list data structure in C++
- Stack data structure in C++
- Queues data structure in C++
- File handling with C++ programming
- Date and time handling in C++ programming
Here is a simple C++ program.
#include<iostream> using namespace std; int main() { cout<<"C++ Tutorial at codescracker.com"; return 0; }
When the above C++ program is compiled and executed, it will produce the following output:
The preceding program was written, compiled, and executed in one of the most well-known IDEs for C++ programming. Let's take a look at another C++ example program.
// C++ Programming Tutorial - C++ Tutorial with Examples
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << "Enter your name: ";
getline(cin, name);
cout << "\nHey,\n" << name;
cout << "!\nAre you ready?";
cout << endl;
return 0;
}
The following snapshot shows the initial output produced by the above C++ program.
Now type your name, say "Julia Roberts," and hit the ENTER key to produce the following output:
You will learn all about C++ programming, one by one, in this tutorial series.
Audience
This tutorial is designed and developed to help all those C++ programmers, who are interested in practice a lot of programs in C++, along with its description and tutorial.
We have included as many posts as are required to learn C++, along with its tutorial and examples.
In this tutorial series, we have included as many programs as required in each and every posts.
Prerequisites
Before you start learning the C++ programming given here, you must have some basic computer skills. If you have it, then you can understand how to setup your environment to start programming in C++.
And if you know how to program, then it becomes very easy to learn C++ here.
« CodesCracker Home Next Tutorial »