Conditional operator " ? : "

Viewed 953

I've done my programming exam in C yesterday. There was a question I could not answer, and even though I've studied today I can't come up with a solution.

So we have this:

int A= -1 , B= -2, C= -3, X=1;
X = B != C ? A=(~C) - A-- : ++C + (~A);
printf("A= %d  B= %d  C =%d  X=%d \n", A,B,C,X);

I know this operator functions if X = B != C is true then A=(~C) - A-- is executed. If it's false, ++C + (~A) is executed.

Can anyone tell me and explain what are the values of A, B, C and X in that printf?

NEW

This was included in a question that asks to do a "trace" to the whole program:

     #include <stdio.h>
            void main(){
            int A= -1 , B= -2, C= -3, X=1;

        X = B != C ? A=(~C) - A-- : ++C + (~A);
        printf("A= %d  B= %d  C =%d  X=%d \n", A,B,C,X);

if(~A){
        printf("\n out1\n");
        C= A | B
        printf("A= %d  B= %d  C =%d  X=%d \n", A,B,C,X);
        C= C <<1;}

if(A^B){
         printf("\n out2\n");
        C= B & A
        B += 2
        X= X>>1
        printf("A= %d  B= %d  C =%d  X=%d \n", A,B,C,X);

By the way can anyone tell me what does it mean those if conditions?

3 Answers
Related