My Report

C# Basic Online Test – 2


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. Scope of variable is related to definition of variable as:
i. Region of code within which variable value is valid and hence can be accessed.
ii. No, relation with region where variable is declared its value is valid in entire scope.

2. Choose the correct type of variable scope for the following C# defined variables.

  class ABC
  {
      static int m;
      int n;
      void fun (int x , ref int y, out int z, int[] a)
      {
         int j = 10;
      }
  }
 

3. 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

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

  static void Main(string[] args)
  {
      int i ;
      for (i = 0; i < 5; i++)
      {
          int j = 0;
          j += i; 
          Console. WriteLine(j);
      }
      Console. WriteLine( i * j);
      Console. ReadLine();
  }
 

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

    public static void Main(string[] args)
    {
        int i = 123;
        object o = i;
        i = 456;
        System. Console. WriteLine("The value-type value = {0}", i);
        System. Console. WriteLine("The object-type value = {0}", o);
        Console. ReadLine();
    }
  

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

 
class Program
{
    static void Main(string[] args)
    {
        int  i ;
        for (i = 0; i < 5; i++)
        {
            Console.WriteLine(i);
        }
        Console.ReadLine();
    }
}

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

 class Program
 {
     public static void Main(string[] args)
     {
         int i = 100;
         for (a = 0; a < 5; a++)
         {
             int i = 200;
             Console. WriteLine(a * i);
         }
         Console. ReadLine();
     }
 }
  

8. Choose effective differences between 'Boxing' and 'Unboxing'.

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

 
  public static void Main(string[] args)
  {
      int i = 546;
      object o = i;
      int n =(int) o;
      o = 70;
      System. Console. WriteLine("The value-type value = {0}", n);
      System. Console. WriteLine("The object-type value = {0}", o);
      Console. ReadLine();
  }
  

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

 class Program
 {
     public static void Main(string[] args)
     {
         int i, j;
         i = (j = 5) + 10;
         Console. WriteLine(i);
         Console. WriteLine(j);
         Console. ReadLine();
     }
 }
  

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

 class Program
 {
     static void Main(string[] args)
     {
         int i;
         for ( i = 0; i < 5; i++)
         {
                
         }
         Console. WriteLine(i);
         Console. ReadLine();
     }
}

12. Syntax for declaration and initialization of data variable is?

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

 class Program
 {
     static void Main(string[] args)
     {
         int i ;
         for ( i = 0; i < 5; i++)
         {
             int j = 0;
             j += i; 
             Console. WriteLine(j);
         }
         Console. WriteLine(i);
         Console. ReadLine();
     }
 }

 

Start practicing “1000 MCQs on C#”, and once you are ready, you can take tests on all topics by attempting our “C# Test Series”.

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.