INTRODUCTION TO C++
C language is an powerful programming language However, it did have one significant limitation
it lacked support for object-oriented programming Object-oriented programming allows smart
programmers like you to organize code into reusable units called classes. Recognizing this
need for object-oriented programming support, Bjarne Stroustrup, a Danish computer scientist,
decided to extend the capabilities of the C language Stroustrup initially referred to this new
language as "C with Classes."
In 1983, the language underwent a significant transformation, leading to its new name C++
Now, let's explore the basics of C++ language in just 10 minutes. This is a basic C++ program
that prints hello world in the terminal. A C++ program ends with .cpp extension. Let's break this
down. The first line is #include <iostream> This #include tells the compiler to include all the
code from the iostream header file, which provides objects like cout to print data in the terminal
Every C++ program should have a main function, just like in C
A function is declared by specifying the return type of the function, which is int in this case since
we are returning 0 at the end. Then the name of the function is specified, followed by any
arguments in parentheses, and finally the body of the function in curly brackets When I saw this
line for the first time, I was like what type of sorcery is this? How are we passing data to the
cout object without using parentheses, and what is the purpose of the left shift operator (<<)?
Also, what does
the double colon (::) mean? If you have the same questions, don't worry, I'll explain it to you.
With the help of this line, we are printing "Hello, World!" in the terminal. In C++, this operator is
called the insertion operator when used with cout. It is used to format the data according to its
data type and then send it to the cout object, which displays it in the terminal. The basic
function of this operator is to shift bits to the left, but its behavior can be changed through the
concept of operator overloading in C++
Operator overloading allows you to give different meanings to operators, but since this is the
beginners video won't go into detail about this operator overloading. Now, if you include multiple
libraries in your code, there might be another cout object somewhere in those libraries. So, how
will your compiler know which cout object to use? It knows by using this scope resolution
operator ( :: ). When we write std::cout we are telling the compiler to use the cout object from
the std namespace.
The std namespace is available through the iostream header file. You might be familiar with
classes and functions, but what about namespaces? A namespace is a feature in C++ that
allows you to group related code together to avoid naming conflicts. Think of it like this a single
line of code is a statement, a group of statements creates a function, and a group of functions
and variables creates a class Similarly, a collection of different classes, objects, functions, and
variables forms a namespace
C language is an powerful programming language However, it did have one significant limitation
it lacked support for object-oriented programming Object-oriented programming allows smart
programmers like you to organize code into reusable units called classes. Recognizing this
need for object-oriented programming support, Bjarne Stroustrup, a Danish computer scientist,
decided to extend the capabilities of the C language Stroustrup initially referred to this new
language as "C with Classes."
In 1983, the language underwent a significant transformation, leading to its new name C++
Now, let's explore the basics of C++ language in just 10 minutes. This is a basic C++ program
that prints hello world in the terminal. A C++ program ends with .cpp extension. Let's break this
down. The first line is #include <iostream> This #include tells the compiler to include all the
code from the iostream header file, which provides objects like cout to print data in the terminal
Every C++ program should have a main function, just like in C
A function is declared by specifying the return type of the function, which is int in this case since
we are returning 0 at the end. Then the name of the function is specified, followed by any
arguments in parentheses, and finally the body of the function in curly brackets When I saw this
line for the first time, I was like what type of sorcery is this? How are we passing data to the
cout object without using parentheses, and what is the purpose of the left shift operator (<<)?
Also, what does
the double colon (::) mean? If you have the same questions, don't worry, I'll explain it to you.
With the help of this line, we are printing "Hello, World!" in the terminal. In C++, this operator is
called the insertion operator when used with cout. It is used to format the data according to its
data type and then send it to the cout object, which displays it in the terminal. The basic
function of this operator is to shift bits to the left, but its behavior can be changed through the
concept of operator overloading in C++
Operator overloading allows you to give different meanings to operators, but since this is the
beginners video won't go into detail about this operator overloading. Now, if you include multiple
libraries in your code, there might be another cout object somewhere in those libraries. So, how
will your compiler know which cout object to use? It knows by using this scope resolution
operator ( :: ). When we write std::cout we are telling the compiler to use the cout object from
the std namespace.
The std namespace is available through the iostream header file. You might be familiar with
classes and functions, but what about namespaces? A namespace is a feature in C++ that
allows you to group related code together to avoid naming conflicts. Think of it like this a single
line of code is a statement, a group of statements creates a function, and a group of functions
and variables creates a class Similarly, a collection of different classes, objects, functions, and
variables forms a namespace