L
L. Spiro
Guest
Not too hard, but a good tester of just how intimate you are with the language.
Obviously the solutions to all of these problems can be found by simply compiling the code and viewing the results, but that defeats the purpose entirely.
Try to see how many of these you know right off the top of your head.
These are all my own original questions, by the way.
DISCLAIMER: THESE QUESTIONS ARE NOT INTENDED TO BE EXAMPLES OF QUALITY CODE. IN FACT, THE ANSWERS TO MOST THESE QUESTIONS DEMONSTRATE EXACTLY WHY YOU SHOULD NOT CODE THIS WAY.
1:
Code: [Select]
What is the value of J?
2:
Code: [Select]
What is the value of I after this entire code segment is processed? Why is this significant?
3:
Code: [Select]
What is the value of J?
4:
Code: [Select]
What is the result of this expression and why?
L. Spiro
Obviously the solutions to all of these problems can be found by simply compiling the code and viewing the results, but that defeats the purpose entirely.
Try to see how many of these you know right off the top of your head.
These are all my own original questions, by the way.
DISCLAIMER: THESE QUESTIONS ARE NOT INTENDED TO BE EXAMPLES OF QUALITY CODE. IN FACT, THE ANSWERS TO MOST THESE QUESTIONS DEMONSTRATE EXACTLY WHY YOU SHOULD NOT CODE THIS WAY.
1:
Code: [Select]
Code:
int I = 30;int J = ((I++) + I++);
2:
Code: [Select]
Code:
int I = 0;int J = 0;if ( I++ == 1 && I++ == 2 ) { J = 1; }
3:
Code: [Select]
Code:
int I = 0;int J = ( I++ == 1 || ++I == 1 ) ? ++I : I++;
4:
Code: [Select]
Code:
(int *)6 - (int *)2
L. Spiro