Special Operators:


C supports some special operators of interest such as comma operator, sizeof operator, pointer operator (& and *) and member selection operators (. and ->). The comma operator and sizeof operator are discussed in this section.


The Comma Operator:
The comma operator can be used to link the related expressions together. A comma- linked list of expressions is evaluated left to right and the value of right most expression is the value of the combined expression. For example, the statement
                        value = (x = 10, y = 5, x+y);
first assigns the value 10 to x, then assigns 5 to y, and finally assigns 15 (i.e. 10 + 5) to value. Since comma operator has the lowest precedence of all operators, the parentheses are necessary. Some applications of comma operator are:
Ø  for Loops
Ø  while Loops
Ø  Exchanging values



The sizeof operator:
The sizeof is a compile time operator and, when used with an operand, it returns the number of bytes the operand occupies. The operand may be a variable, constant or a data type qualifier.
Example:
                        m= sizeof (sum);
                        n= sizeof (long int);
                        k= sizeof(235L);

The sizeof operator is normally used to determine the lengths of array and structures when their size is not known to the programmer. It is also used to allocate memory space dynamically to variables during execution of a program.

Previous                                                                                    Next


Powered by Blogger.