hello everyone welcome to Java tea point for today's our topic of discussion is
first programming C++ this is a very very important topic actually or we can
say this is the first step to learn C++ programming so let's begin so in this
video we are going to cover these three topics first is how to write the code
second is how to compile the code and third is how to execute the code so to
write the code we need to understand the programming structure of C++ so
components of C++ structure there are mainly three sections in C++ program the first one is standard library section the second one is main
function section the third one is function body section first we will look
at the standard library section the standard library section it consists of
two statements the first one is hash include iostream and the second one is
using namespace std here hash include is a preprocessor command that includes all
the files of a header file in your program and here head here iostream is a
header file which must be specified within these angular brackets so iostream
is a header file that contains the two most commonly used objects that is cin
and cout where cin is an object of input stream that uses an insertion
operator to take an input from the user while cout is an object of output stream
that displays the output on the screen and it uses an extraction operator so
the second statement is using namespace std here the significance of namespace
is that it removes the ambiguity or it avoids the collision between the
similar function names or the similar variable names for example suppose there are two person having the similar name like Akash so how we can call them
or how we refer them we can call them either through the area or through the
their parents name in the similar way C++ contains various libraries that are
having the similar functions names so how compiler can recognize this function
to which our program is referring so this problem is overcome by using the
concept of namespace so in C++ std here what std is std is a predefined
namespace in C++ the functionality of cin and cout defined in std namespace so
to use the cin and cout object in your C++ program you have to use the std
namespace so if in your program if you are not using the namespace std then you
need to prefix std then scope resolution operator before the cin and cout like
this so to avoid prefixing this we can use the namespace std like this so if we
are using the namespace std then we don't have to prefix std before the
cin and cout we can directly access cin and cout so the next section is the
main function section here the main function is the starting or the beginning
function of all the C++ programs and here end is the return type of the main
function and the body of the function starts with the opening of the curly
brackets and the ends with the closing of the curly bracket the next section is
function body section now after adding the main function we have to write the
statements in a main function body so what are the statements then the
statements are those like suppose I want to create a program that adds two
numbers so I have to create a logic that will add two numbers so the logic which
we which I write are the statements so after writing the statements I have to
write the return statement this is the end statement of the main function so
basically what what is the significance of return statement here return statement basically used to terminate the execution it either returns the
control to the operating system or to the calling function and the value which
we are passing with the return statement should match with the return type of the
function suppose I am writing here into type so the value must be of integer
type and if I am writing here float so value must be a floating type all right
them so the value should be match with this return type and if I am using the
void type then it is optional to use the return statement so let's understand
this return statement through a simple example here we have used a simple very
very simple example so we have created a main function in which we are calling a
display function which is a user-defined function when we are calling a display
function the control moves to that user-defined function then this all these
statements of this function will be executed then after the execution of
these statement the control moves back to the statement from which the from
where the function is being called okay then after the execution of all the
statements of a main function the control comes to the return statement
and this return statement will terminate the program and returns the control to
the OS that is operating system so now let's look at the practical
implementation of our first C++ program here we are using we are creating our
first C++ program in Dev C++ compiler so here we'll see how to write how to
compile and how to execute the code so first we will include our header file
hash include and I'm using a iString as a header file then we have to use the
namespace and get a main function then we'll write the body of the main
function suppose I want to print hello Java t point on the console to print
something on the console we have to use a C out then extraction operator so to
print something on that should be that should come within the double quits
hello Java t point and this statements ends with the statement terminator now
after writing the logic of a program we have to write the return statement now
to compile and execute this code we will press function key f11 Wow we got
the output hello Java t point so thank you everyone for watching this video so
if you like this video then please like and subscribe it