Type casting
The process of converting one predefined type into another is called type casting.
type conversion have two forms:implicit type conversion
explicit type conversion
Implicit type conversion:- the process of converting one predefined type into
another performed by compiler without programmers intervention. it is applied
generally whenever different data types are intermixed in an expression.
ex:- long double
It either operand is of type long double the other is converted to long double.
Explicit type conversion:- Explicit type conversion is user defined that forces an
expression to be a specific type.
ex:-void main ()
{
int x=65;
cout<<x<<endl;
cout<<(char)x; //explicit type casting
}
output:- 65
A
C ++ shorthands
C++ offers special shorthands that simplify the coading of certain type
of assignment statements.
ex:- a=a+10
can be written as,
a+ =10
some examples of c++ shorthands:-
X- =10
X*=3
X/=2
X%=z
Equivalent
to
Equivalent to
Equivalent to
Equivalent to
X= X-10;
X=X*3;
X=X/2
X=X/Z
Void fun1
{
int a; /* local to fun1 block*/
}
void ()
{
int i, sum=0; //sum is declared as static variable
for (i= 0; i<=10; i++)
{
sum= sum +i;
}
cout<<\nSum is =<<sum;
}
Extern:- variable when defined outside the program file but used in
the current file are used after linked them using extern keyword in
declaration.
Register:- its concept is in low level programming language there is
no any use in high level language.