Thursday, December 3, 2020

Getting started with C++.

 Learn programming for free


Getting started with C++.


In this blog we will learn about fundamentals of C++.For example how to take input,how to print output etc.This is what every student who wants to learn c++ should definitely know.


So let's understand all these things with very basic example:


#include<iostream>
using namespace std;
int main()
{
int a,b,sum=0;
cout<<"Enter first number";
cin>>a;
cout<<"Enter second number";
cin>>b;
sum=a+b;
cout<<"Sum is"<<sum;
return 0;
}


Above program is used to find sum of two number in c++.Now understand each line of above code in detail.

1. #include<iostream>

In programming language we call it as header file,which includes all details required to carry out current program.Like in our case we are taking two input from user so this header file includes all functionalities required to take input from user.


2.using namespace std

Here this line is used so that we can use all standard things in c++.

For example if  we don't use this line then for writing cin we have to write syntax as

std::cin>>

otherwise we write syntax as cin>>


3.int main()


This is a function don't worry we will learn it in depth here just remember it that it is simply a function.


4.cout<<"Enter first number";

This statement is used to print  information on screen.Like in our case it is will print Enter first number.


5.cin>>a;


This statement is used to take input from user.In our case it will take input from user as an integer.


6.sum = a+b;

I don't think this statement needs any explanation.This is a simple arithmetic operation.It will store sum of a and b into sum variable.

7. Finally it will print sum of two number as a result.


If you want to learn c language in depth then do visit : learn c language in depth.

 

Share this

0 Comment to "Getting started with C++."

Post a Comment

If you have any doubts then let me know.