For the given set of C# code, is conversion possible?
static void Main(string[] args)
{
int a = 76;
char b;
b = (char)a;
Console.WriteLine(b);
Console.ReadLine();
}
a) Compiler will generate runtime error
b) Conversion is explicit type
c) Compiler will urge for conversion from ‘integer’ to ‘character’ data type
d) None of the mentioned
Answer: b
Explanation: Since, given conversion is of explicit type as one data type is in integer and other is in ‘char’. Compiler is needed to make a clear distinction between both type of data types and hence, explicitly one need to specify data type as compiler is unable to make automatic conversion.
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