C quiz questions/answers?

Julian Catchen plug-devel@lists.PLUG.phoenix.az.us
Mon Nov 5 17:01:02 2001


The answer is B.  Although some compilers whine without parentheses around
the "i < 100" line.

Questions on passing by reference versus passing by value is always a good 
question on a C test.

julian

ps - I checked my answer after I came up with a solution.... :)

-----Original Message-----
Date:  Mon, 05 Nov 2001 15:17:00 -0700 
To:  "plug-devel@lists.PLUG.phoenix.az.us"  <plug-devel@lists.PLUG.phoenix.az.us> 
From:  Rob Wehrli <rwehrli@azpower.com> 
Sender:  plug-devel-admin@lists.PLUG.phoenix.az.us 
Subject:  C quiz questions/answers? 
Cc:  


I've been writing an C "test" and thought that I'd ask the list for any
good traps/questions they might have...but not without at least offering
one.

#include <stdio.h>

int main( int argc, char * argv[] )
{
  int x = 100;
  int i = 102;

  i < 100 ? x = i : x = 100;

  printf( "x = %d\n", x );

  return 0;
}


What is the output of the following program:


A: Does not compile, does not execute.
B: x = 100
C: x = 102
D: None of the above

IF A or D, explain your answer:

____________________________________________

____________________________________________

____________________________________________

____________________________________________



(No fair cheating and using a computer!)


Take Care.

Rob!
_______________________________________________
PLUG-devel mailing list  -  PLUG-devel@lists.PLUG.phoenix.az.us
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-devel