Thursday, June 26

SPECIAL OPERATORS used in c++ tutorials


There are some special operators in C++ language to perform particular type of operation. Some of them are as follows:
(a) Unary operators : The unary operators require only a single expression to produce a line. Some of the unary operators are:
(1) Pointer operator (*) : The pointer operator is used to get the content of the address operator pointing to particular memory element or cell...
(2) Address operator (&) : The address operator is used to get the address of the other variable in an indirect manner, we will see their detail description later......
(3) Sizeof operator : The sizeof operator is used to give direction to the C++ compiler to reserve the memory size to the particular data type which is defined in the structure type of data in the linked list, we will leran this operator with full explanation later on
(4) Incrementor and decrementor : They are special operators which controls the loops in the c++ program.......
They are denoted by ++ or -- as :
++i ; is equal to i = i+1;
--i; is equal to i= i-1;
Generally they increment and decrement value of i by 1 or more.......
(5) Cast operator : There are situations , where some variables are declared as integers but sometimes it may be required to get the result as floating point numbers. The type conversion is to convert the set of declared data type to some other required type. C++ provides a specific and a special way for converting one data type to the other using a cast operator....

(b) Ternary operator (?:) C++ includes a very special operator called ternary or conditional operator. It is called ternary because it uses three expressions. The ternary operator is the shorthand version of 'if-else' construction. The general format of ternary operator is :

expression 1 ? expression 2 : expression 3
which results in either expression 2 or expression 3 is being evaluated. If expression 1 is true, then expression 2 is evaluated; otherwise expression 3 is evaluated....... for example:
if(x%2 == 0)
even = TRUE;
else
even = FALSE;
Above expression can be written as : even = (x % 2 ==0) ? TRUE : FALSE;
(c) Comma operator : In two ways it is represented : one for seperator of variable declaration as:
int a,b,c;
float x,y,z;
and other will be disscussed later....
(d) Scope operator (::) : The double colon :: is used as the scope resolution operator in C++. The scoping operator is used in a class member function definition, disscussed in detail later.........
(e) New and Delete operators : In traditional C the dynamic memory allocation and deallocations was done through library functions such as calloc,malloc,alloc and free routines..... C++ defines a new method for carrying out memory allocations and deallocations, using new and delete operators
(f) Parentheses for grouping expression : In this parentheses () are put in the side of variable to avoid precedence rule as:
(a+b)*c would cause addition to be performed first than multiplication, where as a+b*c would cause multiplication first......
(g) Membership operator : To represent a variable membership operators are used which are represented as [] and ->, detail discussion later.....
That's end our topic of special operators do come tomorrow for new topic "TYPE CONVERSION"

0 comments:

Followers

Archive

 

Money ,Entertainment and Education. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com