Home / C# Programming / Structures :: General Questions

C# Programming :: Structures

  1. The space required for structure variables is allocated on stack.

  2. A.
    True
    B.
    False

  3. Creating empty structures is allowed in C#.NET.

  4. A.
    True
    B.
    False

  5. Which of the following will be the correct output for the C#.NET program given below?

      namespace FreshergateConsoleApplication
      {    
           struct Sample  
           {        
                public int i;    
           }  
           class MyProgram   
           {      
               static void Main()     
               {         
                   Sample x = new Sample();              
                   x.i = 10;    
                   fun(x);              
                   Console.Write(x.i + " ");     
                }       
                static void fun(Sample y)  
                {         
                      y.i = 20;              
                      Console.Write(y.i + " ");           
                }   
            } 
        }
    

     

     

  6. A.

    10 20

    B.

    10 10

    C.

    20 10

    D.

    20 20

    E.

    None of the above


  7. Which of the following is the correct way of setting values into the structure variable e defined below?

    struct Emp 
    {   
          public String name;  
          public int age;   
          public Single sal; 
     }
      Emp e = new Emp();
    

  8. A.
     e.name = "Amol"; 
     e.age = 25; 
     e.sal = 5500;
    B.
     With e
     {   
       .name = "Amol";   
       .age = 25;    
       .sal = 5500;  
     }
    C.
    With emp e 
    {    
          .name = "Amol";   
          .age = 25;     .
           sal = 5500;  }
    D.
     e -> name = "Amol"; 
     e -> age = 25; 
     e -> sal = 5500;
    E.
     name = "Amol"; 
     age = 25;
     sal = 5500;

  9. Which of the following is the correct way to define a variable of the type struct Emp declared below?

    struct Emp 
    {  
        private String name;   
        private int age;   
        private Single sal; 
    }
    1. Emp e(); e = new Emp();
    2. Emp e = new Emp;
    3. Emp e; e = new Emp;
    4. Emp e = new Emp();
    5. Emp e;

     

  10. A.

    1, 3

    B.

    2, 5

    C.

    4, 5

    D.

    1, 2, 4


  11. Which of the following statements is correct about the C#.NET code snippet given below?

     class Trial
     {   
         int i;    
         Decimal d;
     }
     struct Sample
     {  
         private int x;  
         private Single y;    
         private Trial z; 
      }
      Sample ss = new Sample();

     

  12. A.

    ss will be created on the heap.

    B.

    Trial object referred by z will be created on the stack.

    C.

    z will be created on the heap.

    D.

    Both ss and z will be created on the heap.

    E.

    ss will be created on the stack.


  13. How many bytes will the structure variable samp occupy in memory if it is defined as shown below?

    
    class Trial 
    {    
         int i;    
         Decimal d; 
     }  
     struct Sample 
     {   
         private int x;   
         private Single y;    
         private Trial z;
     }
     Sample samp = new Sample();
    

  14. A.

    20 bytes

    B.

    12 bytes

    C.

    8 bytes

    D.

    16 bytes

    E.

    24 bytes


  15. Which of the following will be the correct result of the statement b = a in the C#.NET code snippet given below?

     struct Address 
     {   
         private int plotno; 
         private String city;
     } 
     Address a = new Address(); 
     Address b; 
     b = a;
    

  16. A.

    All elements of a will get copied into corresponding elements of b.

    B.

    Address stored in a will get copied into b.

    C.

    Once assignment is over a will get garbage collected.

    D.

    Once assignment is over a will go out of scope, hence will die.

    E.

    Address of the first element of a will get copied into b.


  17. Which of the following statements are correct?

    1. A struct can contain properties.
    2. A struct can contain constructors.
    3. A struct can contain protected data members.
    4. A struct cannot contain methods.
    5. A struct cannot contain constants.

  18. A.
    1, 2
    B.
    3, 4
    C.
    1, 2, 4
    D.
    3, 5

  19. C#.NET structures are always value types.

  20. A.
    True
    B.
    False