What is Special Operator in C programming language ?

In this article we will be going to talk about some special operator which is available in C language like,

  • The Comma Operator
  • The sizeof Operator

What is Special Operator in C language ?

Special Operator in C:

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

The Comma Operator in C:

The comma operator is in C language is used to link the related expressions together. A comma-linked list of expressions are 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 assign 5 to y, and finally assign 15(i.e 10+5) to value. Since comma operator has the lowest precedence of all operator,the parenthesis are necessary.Some application of comma operator are:

In for loop:   for(n=1,m=10,n<=m;n++,m++)

In while loop: while(c=getchar(),c!='10')

Exchange value: t=x, x=y, y=t;

The sizeof Operator in C

The sizeof is a compile time operator and when used with operand,it return the number of bytes the operand occupies.The operand may be variable, a constant or datatype qualifier.

Examples:

m=sizeof(sum);
n=sizeof(longint);
k=sizeof(235L);

The sizeof operator is normally is used to determine the lengths of array and structure when their sizes are not known to the programmer.it also used to allocate memory space dynamically to variable during the execution of the a programmer.

Conclusion:

In this article we have learned about two special operator in C language which is comma and sizeof operator i hope you have understand all concept but if you have remaining any doubt then feel free comment blow.
Post a Comment (0)
Previous Post Next Post