1. ==
  2. =
  3. None

1 is the correct answer.
Explanation: == is equal to operator. it checks whether RHS is equal to LHS or not. = is assignment operator that assigns right hand side constant to left hand side variable.

Q2. Read the following sentences.

  • Right hand side value of an equation is equal to left hand side value.
  1. Left hand side value of an equation is equal to right hand side value.

Which statement is true?

  1. 2 Only
  2. 1 Only
  3. Both
  4. Both statements are false

3. Both is the Correct Answer
Explanation: ‘equal to’ operator checks the equality of entities on both side. It’s assignment operator that assigns right hand side value to left hand side variable only.

int main()
{
 int B = 5;
 int A;
 A = B == 6;
 printf("%d",A);
}
  1. 5
  2. 0
  3. 1
  4. 6

Option 2 is correct.
Explanation: In the statement, A = B == 6 Because of the assignment operator between A & B. Compiler will try to solve the equation B == 6 first. == is equal to operator that will check whether RHS is equal to LHS or not. B is equal to 5 hence not equal to 6 so it will return 0 that represents ‘False’. now this value 0 will be assigned to variable A by assignment operator. sequence of execution: A = B == 6; A = 5 == 6; (Variable B will be replaced by it’s value) A = 0; (Because 5 is not equal to 6)

int main()
{
 int B = 5;
 int A;
 if (B = 6)
 printf("%d",B);
}
  1. Nothing will print because printf statement will not run.
  2. Error
  3. 6
  4. 5

Option 3 is correct.
Explanation: Trick is in the codition of if statement. B = 6 is not a condition but a statement that will update value of B to 6. compilation sequence: if ( B = 6) if (6) Because if has a non-zero value that will act as not-false or True so printf statement will run and print value of B i.e. 6.

int main()
{
 int B = 5;
 int A;
 if (B == 6)
 printf("%d",B);
}
  1. Print nothing because there are errors in program.
  2. Print nothing but there are no error in program.
  3. 6
  4. 5

Option 1 is correct
Explanation: Sequence of execution: if (B == 6) if (5 == 6) [ Value of B ] if ( 0 ) [ Because condition is false ] so printf statement will not run and this program will print nothing but there is no error.

int main()
{
int B = 5;
int A;
if (B == 6);
printf("%d",B);
}
  1. Nothing will print because printf statement will not run.
  2. Error
  3. 6
  4. 5

Option 4 is correct There is a semicolon ( ; ) after if statement so it does not matter whether condition is true or false. printf statement will run always.

int main()
{
 int B = 5;
 int A;
 if (B = 6);
printf("%d",B);
}
  1. Print nothing but there are no error in the program
  2. Error
  3. 5
  4. 6

Option 4 is correct. There is a semicolon after if statement so printf statement will always run. But because of condition in if statement B will become 6. so 6 will print.

int main()
{
 int B = 5;
 int A;
 if (A = 6 == 5)
 printf("%d",B);
 printf("\t %d",A);
 return 0;
}
  1. 0
  2. 5 0
  3. 5 6
  4. Error

Option 1 is correct.. Condition in if statement will execute in this sequence. if ( A = 6 == 5 ) if ( A = 0) [ because 6 is not equal to 5 ] if ( 0 ) [ because A is 0 ] printf statement inside if will not run. 0 will print because this is the value of A.

int main()
{
 int B = 5;
 int A;
 if (A = 6 == 6)
 printf("%d",B);
 printf("\t %d",A);
 return 0;
}

Option 1 is correct. if statement will execute in this manner. if ( A = 6 == 6 ) if ( A = 1 ) [ because 6 is equal to 6 ] if ( 1 ) [ because A is 1 ] because condition is true so printf statement inside if will run and value of B i.e. 5 will print. Value of A will print always i.e. 1 so answer will be 5 1

  1. A = 5;
  2. 5 = A;
  3. A == 5;
  4. 5 == A;
  1. None
  2. All
  3. 1 & 4
  4. 1, 3 & 4

Option 4 is correct Rule: Assignment operator needs a variable at LHS. There is no limitation in equal to operator so 1, 3 & 4 are correct.

Leave a Reply