Language C++----Questions and Answers---Page 1

Question: What is the name of the “-->” operator?
Here's an example:
#include <stdio.h>
int main()
{
     int x = 10;
     while( x --> 0 ) // x goes to 0
     {
       printf("%d ", x);     }
}
 

 

Answer.

--> is not an operator. It is in fact two separate operators, -- and >.
The conditional's code decrements x, while returning x's original (not decremented) value, and then compares the original value with 0 using the > operator.
To better understand, the statement could be written as follows:
while( (x--) > 0 )
or
 
#include <stdio.h>
int main()
{
     int x = 10;
     while( (x--) > 0 ) // x goes to 0
     {
       printf("%d ", x);     }
}

Comments

Popular posts from this blog

Working Torrent Trackers list updated Oct 2016...

142.Keith Hunter JESPERSON

How to Fix VLC does not support UNDF Format : Best Fix