Beginning C++


                   
 



  Beginning with C++

What is C++ ?

C++ is an Object Oriented Programming language, It was developed by Bjarne Stroustrup
at T.S Bel Lab.c++ is an extension of c with additional class construct features . The idea of 
c++ comes from increment operator(++) their by suggested that C++ is an next increment version of C.C++
Is a superset of C so all program of c  can able to run in c++.
The main features of c++ or cpp is class, inheritance, operator overloading, abstraction, function overloading .
Lets see simple c++ program


#include<iostream>
  using namespace std;
 int main()
{
cout<<”This is C++ Programming.”;
}


Header File :
                 We use following #include directories in program.
#include<iostream>
It contains declaration of identifiers like cout  and operator <<  and  cin and operator >>.

Return Type in main :
 In C++ , main() function returns an integer value to the operating system.so every main() function in c++ should contains return type. Otherwise warning or error might occours.
The default return type of all function in c++ is int.

Ex :
 int main
{
///Code//
return 0;
}




Operators in c++ :
In c++ there are two most important operators that is cin and cout or we can also called as input operator and oupput operator respectively.


Output Operator :
 In c++ “cout<<” is the output operators use to print any value  on terminal screen.

Like  cout<<”Hello world”;  

it work like printf statement in c. only here you can not use %d,%s,%c etc. C++ library  automatically recognized that .
It is also called as Insertion Operator.


Input Operator :
 In c++ “cin>>” is the input operators use to get value from user or giving input to program .

Like
cin>>value;  

It work like scanf statement only no need to use %d ,%s etc.
It is also called as extraction or get from operator .because It extract value from keyboard and assign to variable.

Cascading operators :

We can use insertion operator repeatedly. Like

cout<< “sum : ”<<sum;

here first send string sum and then send value of sum. So that we called it cascading output operator.
Same with extraction operator also.

cin>>a>>b>>c;

here first accept and stored value in  a then b then c.



lets see one basic program with cin and cout.

#include<iostream>
int main()
{
int roll;
char name[20],std[20];
cout<<”Enter roll num, name and stdanderd”;
cin>>roll>>name>>std;
cout<<”Roll no is”<<roll<<endl;
cout<<”Name is”<<name<<endl;
cout<<”Standerd is”<<roll<<endl;                             

 //endl use for new line u also write “\n”
}

Try to run this program in your terminal



Some C++ data types, their format specifiers, and their most common bit widths are as follows:

 • Int ("%d"): 32 Bit integer 
 • Long ("%ld"): 64 bit integer
 • Char ("%c"): Character type 
 • Float ("%f"): 32 bit real value
 • Double ("%lf"): 64 bit real value
 ________________________________________ 
Reading To read a data type, use the following syntax:

scanf("`format_specifier`", &val);

For example, to read a character followed by a double: 

char ch;
double d; 
scanf("%c %lf", &ch, &d); 

For the moment, we can ignore the spacing between format specifiers. ________________________________________ 

Printing To print a data type, use the following syntax: 

printf("`format_specifier`", val)

For example, to print a character followed by a double:

 char ch = 'd';
 double d = 234.432; 
 printf("%c %lf", ch, d);

 Note: 

You can also use cin and cout instead of scanf and printf; however, if you are taking a million numbers as input and printing a million lines, it is faster to use scanf and printf.

Comments