© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

Ex - 11: What is the output?

main()
{
      float me = 1.1;
      double you = 1.1;
      if(me==you)
printf("I love U");
else
            printf("I hate U");
}
Answer:
I hate U
Explanation:

For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value  represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.

Ex - 12:  What is the output?
main()
{
      int i=3;
      switch(i)
       {
          default:printf("zero");
          case 1: printf("one");
               break;
         case 2:printf("two");
              break;
        case 3: printf("three");
              break;
        } 
}
Ans:

three
Explanation :

The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.


1 >> 2 >> 3 >> 4
SLogix Student Projects
bottom