Code: #include<iostream.h> void main() { float num=110; (num!=(num=--num))?cout<<"OK":cout<<"NOT OK"; } Give the output with detailed explanation
as per my logic the answer is NOT OK... because see the line (num!=(num=--num))?cout<<"OK":cout<<"NOT OK"; is a ternary operator and the words num=--num means that the num value is decreased by one and it is assigned to num so now the new value of num is 109 and the latter set of staments compares 109 with 109 [ since we know that -- operator decreases it by one so the answer is "not ok" if u need more clear explanation i m ready to explain.. hav a gud day..
The output is undefined because you modify the same variable twice in the same statement. So the output will depend on how the compiler writer felt at the time, and may differ from compiler to compiler and version to version of the same compiler.