Exercise: Structures

Questions for: Structures

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();
A:
The structure variable b will be created on the heap.
B:
We can add a zero-argument constructor to the above structure.
C:
When the program terminates, variable b will get garbage collected.
D:
The structure variable b will be created on the stack.
Answer: D
No answer description is available. Let's discuss.
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.
Answer: C
No answer description is available. Let's discuss.
C#.NET structures are always value types.
A:
True
B:
False
C:
D:
Answer: A
No answer description is available. Let's discuss.
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
Answer: A
No answer description is available. Let's discuss.
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.
Answer: A
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz