Blogger templates

Pages

Monday, 18 June 2012

Tutorial on Special Operators of C Language

Special Operators
Special Operators of C:
  1. Comma Operator
  2. Size of()
  3. Address Operator
  4. Dereferencing Operator
  5. Dot Operator
  6. Arrow Operator
Lets we have to Discuss Some Popular Special Operators of C:

=> Sizeof () Operator:
  • This Operator returns the size(i.e number of bytes) of operand.
  • It should be written in lowercase Letter.
  • The operand may be constant , a variable , or a data type.
  • It is used for dynamic memory allocation.
  • It is also used to determine the size of arrays and structures.
Syntax:

  sizeof (operand); 

Example:
x = sizeof (int);
y = sizeof (sum);

Program of Sizeof () Operator:
Statement: This Program illustrates the use of sizeof () Operator:
{
int a;
float b;
char ch = 'c' ;
a = 2;
b = 10.0;
printf(" Size of a = %d\n" , sizeof (a) );
printf(" Size of b = %f\n" , sizeof (b) );
printf(" Size of ch = %c\n" , sizeof (ch) );
Output:
Size of a = 2
Size of b = 4
Size of ch = 1

=> Shorthand Assignment Operators:
  • C provides a compact way of writing assignment Statements in an Expression.
  • This is basically associated with all arithmetic Operators and bitwise Operators.
Syntax:


  var | operator | = | exp |   

where
var => is a variable
operator => an airthmetic or bitwise operator
exp => is an Expression

NOTE:  
  • There is no space between the operator and the '=' sign in compact representation.
  • Shorthand Assignment operators are easier to read , write and understand.
Program of Shorthand Assignment Operators:
{
int a , b , c;
a = 3;
b = 4;
c = 1;

a += b;
b -= a;
c *= x;

printf("%d\n" , a);
printf("%d\n" , b);
printf("%d\n" , c);
Output:
 7
 -1
 5
                                                         
                                                                  That's All

0 comments:

Post a Comment