C++ programming :
C++ is a general purpose object oriented programming (oop) language developed by Bjarne Stroustrup.
C++ was developed at AT & T's Bell laboratories of USA in early 1980's. It was expended version of 'C'.
Difference between C and C++ :
The major difference between C and C++ is that 'C' is a procedural programming language and does not support class and object, while C++ is a combination of both procedural and object oriented programming language; therefore C++ can be called a hybrid language.
Data types used in C++ :
Data types in C++ can be classified under various categories as shown below
c++ data types -
1) User-defined type-
structure, union, class, enumeration
2) Built in type-
(i) integral - int, char
(ii) void
(iii) floating type - float, double
3) Derived type -
array, function, pointer, reference
Operators used in C++ :
1) All 'C' operators are valid in C++ also.
2) In addition C++ introduce some new operators also.
Stream operators-
:: ( scope resolution operator)
: (colon operator)
・(class member access operator)
endl (line feed operator)
setus (field with operator)
Stream operators -
<< and >> (stream operators) in C++ provide alternative to using printf (), scanf (), and other functions defined in stdio.h.
C in function. The C in function takes input from user.
Syntax- Cin >> variable name ;
(The >> operator is thrown as the extraction or get from operator. It extracts or takes a value from keyboard.
Syntax- Cout << "message" << variable name<< endl ;
(The << operator is thrown as the insertion put the operator. It insert or send the contents of the variable.
Program-
// write a C++ program to enter any two numbers and find out their sum and average
# include < iostream.h >
# include < conio.h >
void main ()
{
into x, y ;
float sum, average ;
Cout << " enter the value of x = " << x << endl ;
Cin >> x ;
Cout << " enter the value of y = " << y << endl ;
Cin >> y ;
sum = x + y ;
average = sum/2 ;
Cout << " sum = " << sum << endl ;
Cout << " average = " << average << endl ;
getch () ;
}
Output :
enter the value of x = 10
enter the value of y = 6
sum = 10 + 6 = 16
average = 10 + 6 / 2 = 8
C++ keywords:
asm double new switch
auto else operator template
break enum private this
case extern protected throw
catch float public try
char for register typedof
class friend return union
const goto short unsigned
continue if signed virtual
default inline sizeof void
delete int static volatile
do long struct while
Added by ANSI C++
bool const_cast dynamic_cast explicit | export false mutable namespace | reinterpret_cast static_cast true typeid | typename using |
No comments:
Post a Comment