Simplilearn
C++ Basics Tutorial
Welcome to this tutorial on C++ basics! In this tutorial, we will cover the basics of C++ programming,
including how to write your first program, types and variables, arrays, strings, control statements
(if/else, for loop, while loop), and functions.
Let's start with an introduction to C++ programming. C++ is a popular programming language
introduced by John Strawstrom in 1979. It was initially called "C with Classes" as it was an extension
to the C language, but later renamed as C++. It is a general-purpose, case-sensitive language that is
precompiled, meaning it converts the source code directly to machine-understandable code. It is an
intermediate-level language as it contains both features of high-level and low-level languages. C++
supports the features of object-oriented programming, procedural programming, and functional
programming as well.
Now, let's move on to our first program in C++, which is the "Hello World" program. In this program,
"Hello World" is printed. It is a very basic program, and we are using the header file "iostream" to
import the necessary features. The main function is used to execute the program, and we are
printing "Hello World" using the "cout" function.
#include <iostream>using namespace std;int main() { cout << "Hello World" << endl; return 0;}
Next, we will cover types and variables in C++. There are different types of data types that act as a
keyword, such as boolean (for true/false values), character (for alphabets and symbols), integer (for
integer values), and float (for decimal values). Variables are used to store values, and the syntax to
define a variable is to mention the data type and the variable name.
Arrays are a collection of similar elements stored in contiguous memory locations. They make it
possible to store multiple values of the same data type into a single variable. The syntax to declare
an array is to mention the data type, the array name, and the number of elements inside the
brackets.
Strings are a collection of characters and are used to represent text in the program. There are two
ways to create a string: C-style strings and string objects. C-style strings are stored in the form of
arrays, while string objects are implemented in the standard library and must be included in the
program using "#include"