retagged by
333 views
2 votes
2 votes

Consider the following function $\text{magic5().}$

void magic5(int x, int y){
    if (condition)
        printf("magic");
}

What condition we can write in “if-statement” such that $\text{magic5(5,5)}$ will print magic?

  1. !(x==5)!=!(y==5)
  2. (x==5)?!(y==5):(x==5)
  3. ((x==5)||(y==5))&&!((x==5)&&(y==5))
  4. None of these
retagged by

1 Answer

2 votes
2 votes

magic(5, 5) is being called

It will print magic if if condition evaluates to true,

$\therefore$ x =5 and y = 5

 

Option A: $!(x==5) != !(y==5)$

                 $ !\text{T} != !\text{T} \implies \text{F} != \text{F}$ i.e. $False$

 

Option B: $(x==5)?!(y==5):(x==5)$

                Since x==5 is true so it will execute $!(y==5)$ i.e. $!True = False$ 

 

Option C:  $((x==5) || (y==5)) \& \& !((x==5) \&\& (y==5)) $

                      $True$ $\& \&$ $!(True)$ $\implies True \&\& False \implies False$

 

Therefore (D) is correct.

edited by
Answer:

Related questions