أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
a) In ifb) In elsec) In ifIn maind) In elseIn main
the Correct answer
d) In elseIn main
Answer: d
Explanation :Usage of ‘=’ operator instead of ‘==’ operator .hence,the condition is not true.
First of all the code written has some errors in it
Let's first clean the code.
Now suppose you assign :
the output result will be :
In If
In main
OR
if you assign :
the output result will be :
In else
In main
Note : Here, In main will render in all situation because it is written out of if else condition.
The program is messed up:
int i =; is an invalid expression. A value must be assigned.
int j=%; is also an invalid expression. Again a value must be assigned.
toInt = Convert fn. does not contain definition of toInt.
Comparison operator equality is "==" instead of "="
The values of i and j are invalid. they are integers. plus your equality condition is wrong (==).
However, if i == j then the answer would be b)
otherwise it's d)
There two things with this program:
1. There are some errors for e.g int i=; int j=%; are wrong statements and compiler will generate compile time error. variables of data type int must be initialized properly by providing some value say int i=0, int j=2; etc.2. The calls to functions Convert.ToBoolean and Convert.ToInt are redundant. Convert.ToInt is normaly used to convert non-int types to int. similarly Convert.ToBoolean is used to convert non-boolean types to boolean. By analyzing the program these two calls are redundant as they main purpose is to check if i==j or not. so replace simply by if(i==j) that will do the same as both variables have same type.
For instance if we ignore compilation issues, following is the output
(d) In else
In main
The program is Right and Working
int i =; which is invalid expression
int j=%; invalid expression
toInt = convert does not contain defination of toInt.
comparison operator equality is == instead of =