My Report

C# Programming Practice Test 1


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Default Type of number without decimal is?

2. Disadvantages of Explicit Conversion are?

3. What will be the output of the following C# code?

 static void Main(string[] args)
 {
     int n = 5;
     int x = 4;
     int z, c, k;
     z = 3 * x * x + 2 * x + 4 / x + 8;
     for (c = 1; c <= n; c++)
     {
         for (k = 1; k <= c; k++)
         {
             Console.Write(Convert.ToString(Convert.ToChar(z)));
             z++;
         }
         Console.WriteLine("\n");
     }
     Console.ReadLine();
 }

4. What will be the output of the following C# code?

  static void Main(string[] args)
  {
      int a = 3, b = 5, c = 1;
      int z = ++b;
      int y = ++c;
      b = Convert.ToInt32((Convert.ToBoolean(z)) && (Convert.ToBoolean(y)) 
       || Convert.ToBoolean(Convert.ToInt32(!(++a == b))));
      a = Convert.ToInt32(Convert.ToBoolean(c) || Convert.ToBoolean(a--));
      Console.WriteLine(++a);
      Console.WriteLine(++b);
      Console.WriteLine(c);
  }
 

5. Select differences between reference type and value type:
i. Memory allocated to 'Value type' is from heap and reference type is from 'System. ValueType'
ii. Memory allocated to 'Value type' is from 'System. ValueType' and reference type is from 'Heap'
iii. Structures, enumerated types derived from 'System. ValueType' are created on stack, hence known as ValueType and all 'classes' are reference type because values are stored on heap

6. Check the following C# code whether the given relation operator works according to the if condition or not.

 static void Main(string[] args)
 {
     int a = 10;
     int b = 5;
     int c = 12; 
     int e = 8;
     int d;
     d = Convert.ToInt32((a * (c - b) / e + (b + c)) <= (e * (c + a) / (b + c) + a));
     Console.WriteLine(d);
     if (d == 1)
     {
         Console.WriteLine("C# is great language!");
         Console.WriteLine((a * (c - b) / e + (b + c)));
     }
     else
     {
         Console.WriteLine("harsh is not great language!");
         Console.WriteLine((e * (c + a) / (b + c) + a));
     }
 }

7. What will be Correct Set of C# Code for given data 'a' and 'b' to print output for 'c' as 74?

8. Correct order of priorities are:

9. Which of the following C# code is used for conversion of hex to string form?

static void Main(string[] args)
{
    string testString = "MIKA@?&^";
    string normal = ConvertHexToString (hex,  System.Text.Encoding.Unicode);
    Console.WriteLine(normal);
    Console.ReadLine();
}

10. Correct way to define a value 6.28 in a variable 'pi' where value cannot be modified?


 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.