C Sample Test,Sample questions

Question:
 
Which of the following statements are correct about Structures used in C#.NET?

A Structure can be declared within a procedure.
Structs can implement an interface but they cannot inherit from another struct.
struct members cannot be declared as protected.
A Structure can be empty.
It is an error to initialize an instance field in a struct.

1. 1 2 4

2.2 3 5

3.2 4

4.1 3


Question:
 
Which of the following statements is correct?

1.A struct never declares a default constructor.

2.All value types in C# inherently derive from ValueType which inherits from Object.

3.A struct never declares a default destructor.

4.In C# classes and structs are semantically same.


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

struct Book
{
    private String name; 
    private int noofpages; 
    private Single price;
}
Book b = new Book();

1.The structure variable b will be created on the heap.

2.We can add a zero-argument constructor to the above structure.

3. When the program terminates variable b will get garbage collected.

4.The structure variable b will be created on the stack.


Question:
  
Which of the following will be the correct output for the program given below?

namespace IndiabixConsoleApplication
{ 
    struct Sample
    {
        public int i;
    }
    class MyProgram
    { 
        static void Main(string[] args)
        {
            Sample x = new Sample();
            Sample y;
            x.i = 9;
            y = x;
            y.i = 5;
            Console.WriteLine(x.i + " " + y.i); 
        } 
    } 
}

1.9 9

2.9 5

3.5 5

4.5 9


Question:
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();

1.20 bytes

2.12 bytes

3.8 bytes

4.16 bytes


Question:
When would a structure variable get destroyed?

1.When no reference refers to it it will get garbage collected.

2. Depends upon whether it is created using new or without using new.

3. When it goes out of scope.

4.Depends upon the Project Settings made in Visual Studio.NET.


Question:
Which of the following are true about classes and struct?

1. A class is a reference type whereas a struct is a value type.
2. Objects are created using new whereas structure variables can be created either using new or without using new.
3. A structure variable will always be created slower than an object.
4. A structure variable will die when it goes out of scope.
5. An object will die when it goes out of scope.

1.124

2.35

3.24

4.345


Question:
Which of the following statements are correct about the structure declaration given below?struct Book{    private String name;     protected int totalpages;     public Single price;     public void Showdata()    {        Console.WriteLine(name + " " + totalpages + " " + price);    }     Book()    {        name = " ";         totalpages = 0;        price = 0.0f;     } } Book b = new Book();We cannot declare the access modifier of totalpages as protected.We cannot declare the access modifier of name as private.We cannot define a zero-argument constructor inside a structure.We cannot declare the access modifier of price as public.We can define a Showdata() method inside a structure.

1.1 2

2.1 3 5

3.2 4

4. 3 4 5


Question:
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.

1.12

2.34

3.124

4.35


Question:
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();

1.ss will be created on the heap.

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

3.z will be created on the heap.

4.ss will be created on the stack.


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

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

1.20 10

2.10 20

3.10 10

4.20 20


Question:
Which of the following will be the correct output for the C#.NET program given below?  namespace IndiabixConsoleApplication {      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 + "" "");         }      }  } 

1.10 20

2.10 10

3. 20 10

4. 20 20


Question:
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;

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

2.Address stored in a will get copied into b.

3.Once assignment is over a will get garbage collected.

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


More MCQS

  1. C# MCQS -Programming (.NET Framework)
  2. C# MCQS -Programming(Control Instructions)
  3. C# MCQS - Functions and Subroutines(.NET Framework)
  4. C# Programming-Constructors
  5. C# Programming- Arrays
  6. C# Programming -Structures
  7. C# Programming-Properties
  8. C# Programming -Exception Handling
  9. C# Programming -Interfaces
  10. C# Programming -Delegates
  11. C# Programming -Generics
  12. C# Programming - Datatypes
  13. C# Programming- Operators
  14. C# Programming -Classes and Objects
  15. NET Programming mcqs
  16. Computer Science Engineering (CSE) .NET Programming
  17. C# Programming Mcq Set 1
  18. C# Programming Mcq Set 2
  19. C#.NET Programming Mcq
Learn ,Learn C Objetive choice questions and answers,C Multiple choice questions and answers,C objective, C questions , C answers,C MCQs questions and answer
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!