adplus-dvertising
1. The space required for structure variables is allocated on stack.
a. True
b. False
c. Maybe
d. Can't say
Discuss
Answer: (a).True

2. Creating empty structures is allowed in C#.NET.
a. True
b. False
c. Maybe
d. Can't say
Discuss
Answer: (b).False

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

namespace CompSciBitsConsoleApplication
{ 
    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 + " ");
        } 
    } 
}
a. 10 20
b. 10 10
c. 20 10
d. 20 20
Discuss
Answer: (c).20 10

4. 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();
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;
Discuss
Answer: (a).e.name = "Amol";
e.age = 25;
e.sal = 5500;

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

1. Emp e(); e = new Emp();
2. Emp e = new Emp;
3. Emp e; e = new Emp;
4. Emp e = new Emp();
6. Emp e;

struct Emp
{
    private String name; 
    private int age; 
    private Single sal;
}
a. 1, 3
b. 2, 5
c. 4, 5
d. 1, 2, 4
Discuss
Answer: (c).4, 5

6. 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();
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. ss will be created on the stack.
Discuss
Answer: (d).ss will be created on the stack.

7. 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();
a. 20 bytes
b. 12 bytes
c. 8 bytes
d. 16 bytes
Discuss
Answer: (b).12 bytes

8. 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;
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.
Discuss
Answer: (a).All elements of a will get copied into corresponding elements of b.

9. 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.
a. 1, 2
b. 3, 4
c. 1, 2, 4
d. 3, 5
Discuss
Answer: (a).1, 2

10. When would a structure variable get destroyed?
a. When no reference refers to it, it will get garbage collected.
b. Depends upon whether it is created using new or without using new.
c. When it goes out of scope.
d. Depends upon the Project Settings made in Visual Studio.NET.
Discuss
Answer: (c).When it goes out of scope.

Page 1 of 17