Which of the conversions are valid for the following C# code?
static void Main(string[] args)
{
int a = 22;
long b = 44;
double c = 1.406;
b = a;
c = a;
a = b;
b = c;
}
a) c = a, b = c
b) a = c, b = a
c) b = a, c = a
d) All of the mentioned
Answer: a
Explanation: Conversion of data type from ‘int’ to ‘double’ is implicit in nature for ‘c = a’ as int is subset of double but same is not applicable for ‘b = c’ as ‘c’ had wider scope of data range then ‘b’ so explicit conversion is needed.
Output :
Error 1: Can not implicitly convert type ‘long’ to ‘int’. An explicit conversion exists (are you missing a cast?).
Error 2: Cannot implicitly convert type ‘double’ to ‘long’. An explicit conversion exists (are you missing a cast?).
Related Posts
What is the output of the given code?
counter=1
if counter<=5
puts (counter)
counter=counter+1What is the output of the given code?
if(a==10 && b=9)
print “true”
else
print “false”
endWhich of the following are used for comparison?
What is the output of the given code?
a=10
b=9
if(a>b)
print (“a greater than b”)
else
print “Not greater”
endAssignment operator is also known as relational operator.
What is the output of the given code?
a=”string”
b=”strings”
if(a==b)
print (“a and b are same”)
else
print “Not same”
endWhat is the output of the given code?
test_1 = 17 > 16
puts(test_1)
test_2 = 21 <= 30
puts(test_2)
test_3 = 9 >= 9
puts(test_3)
test_4 = -11 > 4
puts(test_4)
Join The Discussion