Today we are going to discuss how to declare variables, what are cin,cout functions and we will also write a simple program to add two numbers and display it.
The Syntax of declaring a variable is as follows-

datatype vaiable name ;

here,datatype can be int , float , char ,double ,  bool or void.(A variable of Bool datatype can store two possible values i.e. true or false,0 or 1,etc.).A variable name can be anything following the identifier's rules (discussed in previous posts).Every variable is associated with 2 values , r value and l value.

r value is the datavalue and l value is the memory address of the variable.

Example of variable declaration- float a; , int b; , etc.

The variable declaration can be cascaded as follows if two or more variables have same datatypes.
float a,b,c;

Now,Coming towards the cin(console input) and cout(console output) operations.
As the name suggests, cin (object of a class ifstream of iostream.h) and cout (object of a class ofstream of iostream.h) are used to take the input from the console and store it at a particular memory space and vice versa, respectively.They are implemented by using extraction/insertion operator with it as follows-
cin>>a;//input value in a
cout<<a; //display value in a
they can also be cascaded as follows-
cin>>a>>b;
cout<<a<<b;

Now,as we are familiar with some basic terms and concepts, now its time to implement it. Now we will move towards the coding part along with the concepts and I will also Link My video to each and Every Program.(My earlier videos were on turbo c++ but newer will be on codeblocks or visual c++ as they are latest versions of IDE with newer features).

//Program to Find the Sum of Two Numbers
#include<iostream>
using namespace std;
int main()
{
 int a,b,c;
cout << "Enter values in a and b=";
cin >> a >> b;
c=a+b;
cout << "\nSum=" << s;
return 0;
}
link to video -

Comments

Popular posts from this blog