Thursday, 28 March 2013

C/C++ Puzzles: PART - 30

The "goes to" Operator in C/C++

What is a "goes to" operator in C/C++? Well most of you might not have heard about it. I have come across this operator (-->) in a C/C++ puzzle recently. The program is shown below.

#include<stdio.h>
int main()
{
   int x=10;
   while(x --> 0)
   {
       printf("%d ", x);
   }
   printf("\n\n\n");
   return 0;
}


The Figure Below Shows the Output

The loop iterates until x reaches the value 0. Well the operator is not a standard operator in C. It is just post decrement ( -- ) followed by the greater than operator ( > ).To understand the working of the so called "goes to" operator consider the loop given below.

while(x--  >  0)
{
    printf("\n%d",x);
}

Also read the post on The Rule of Maximal Munch in C/C++ to understand the compilation process of operators. 

No comments:

Post a Comment