Find the output of C#.Net programs | Data Types | Set 3: Enhance the knowledge of C#.Net Data Types concepts by solving and finding the output of some C#.Net programs.
Question 1:
using System;
namespace MyRefDemo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
int A = 10;
Int32 B = 20;
Int64 C = 0;
C = A * B + sizeof(double);
Console.WriteLine(C);
}
}
}
Question 2:
using System;
namespace MyRefDemo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
long double A = 10.32;
Int32 B = 20;
long double C = 0;
C = A * B + sizeof(long double);
Console.WriteLine(C);
}
}
}
Question 3:
using System;
namespace MyRefDemo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
decimal A = 10.32;
Int32 B = 20;
decimal C = 0;
C = A * B + sizeof(decimal);
Console.WriteLine(C);
}
}
}
Question 4:
using System;
namespace MyRefDemo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
decimal A = 10.32M;
int B = 20;
decimal C = 0.0M;
C = A * B + sizeof(decimal);
Console.WriteLine(C);
}
}
}
Question 5:
using System;
namespace MyRefDemo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
float A = 3.14;
Int32 B = 20;
decimal C = 0.0M;
C = (decimal)(A * B + sizeof(double));
Console.WriteLine(C);
}
}
}
Answer 1:
Output:
Explanation:
The above program will print "208" on the console screen. In the above program, we created three variables of types int, Int32, and Int64 respectively.
Let's evaluate the expression:
C = A * B + sizeof(double); C = 10 * 20 + 8; C = 200 + 8; C = 208;
Then the value of variable C that is 208 will be printed on the webpage.
Answer 2:
Output:
Explanation:
The above program will generate syntax error, because long double is not a built-in data type in C#. Here, we use decimal instead of long double.
Answer 3:
Output:
Explanation:
The above program will generate syntax error because here created variable A of decimal type and assigned a double value. Here, we need to use suffix 'M'. Then the correct declaration will be:
decimal A = 10.32M; Int32 B = 20; decimal C = 0.0M;
Answer 4:
Output:
Explanation:
In the above program, we created three variables A, B, and C initialized with 10.32M, 20, and 0.0M respectively.
Let's evaluate the expression,
C = A * B + sizeof(decimal); C = 10.32 * 20 + 16; C = 206.40 + 16; C = 222.40;
Then the value of C that is 222.40 will be printed on the console screen.
Answer 5:
Output:
Explanation:
The above program will generate syntax error because here created variable A of float type and assigned a double value. Here, we need to use suffix 'F'. Then the correct declaration will be:
float A = 10.32F;
need an explanation for this answer? contact us directly to get an explanation for this answer