The Naughty `C'

For Novice and Intermediate C Programmers

To get the answer highlight the answer line ( It may not be there )

     
  • Find MAXIMUM of three distinct integers using a single C statement

          Ans : d= (a>b) ? ((a>c) ? a : c)) : ((b>c) ? b : c ))

  • Swap two variables without using any extra variable

          Ans : a=a+b;b=a-b;a=a-b;

  • Construct a doubly linked list using a single pointer in each node

          Ans :

  • int i=0; while(i=0) printf("%d",++i); Guess the output

          Ans : The Loop is not executed, since the assignment statement returns the assigned value zero which is equivalent to false in C

  • int i=0; while(i=1) printf("%d",++i); Guess the output

          Ans : The Loop is executed forever always printing 2, since the assignment statement returns the assigned value one which is equivalent to true in C

  • int x=2, y=6, z=6; x=y==z; printf("%d",x); Guess the output

          Ans : The == has higher precedance than