Choose the correct statement among the following which supports the fact that C# does not allow the creation of empty structures?
a
C#.NET supports creation of abstract user-defined data types using structures
b
By having empty structures,it would mean that the new data types have no data associated with, which does not make any sense in C#.NET
c
Basic reason to create structures is the inability to represent real life objects using standard data types offered by the language
d
All of the above mentioned
correct answer d
Basic definition of structures in C#.NET.
2
Which of the following is a correct statement about the C#.NET code given below?
struct book
{
privateString name;
privateint pages;
private Single price;
}
book b =new book();
a
New structure can be inherited from struct book
b
When the program terminates, variable b will get garbage collected
c
The structure variable ‘b’ will be created on the stack
d
When the program terminates, variable b will get garbage collected
correct answer c
Answer: Option (C)
3
Choose the correct statement about structures as to why they are defined as value types but not reference types?
a
Since space required for structure variables is allocated on stack which is a form of memory that is automatically available when a variable to be used is in scope
b
Structures generally are used to represent user defined data types that consists of small amount of data in them.Hence using stack for declaration of such variables is not a problem.
c
All of the mentioned
d
None of the mentioned
correct answer c
Answer: Option (C)
4
Which of the following is the correct way to settle down values into the structure variable ‘e’ defined in the following code snippet?
struct emp
{
publicString name;
publicint age;
public Single sal;
}
emp e =new emp();
a
e.name = “Ankit”; e.age = 24; e.sal = 200;
b
With emp e { .name = “Ankit”; .age = 24; .sal = 200; }
c
name = “Ankit”; age = 24; sal = 200;
d
All of the above mentioned
correct answer a
Answer: Option (A)
5
Select the correct statements among the following?
a
A structure can contain properties
b
A structure can contain constructors
c
A structure can contain protected data members
d
A structure cannot contain constants
correct answer a,b
Answer: Option (A) and Option (B)
6
Which of the following is a correct statement about the C#.NET code given below?
class trial
{
int i;
float d;
}
struct sample
{
privateint x;
private Single y;
private trial z;
}
sample s =new sample();
a
trial object referred by z is created on the stack
b
z is created on the heap
c
Both s and z will be created on the heap
d
s will be created on the stack
correct answer d
Answer: Option (D)
7
Choose the correct statement about structures in C#.NET?
a
Structures can be declared within a procedure
b
Structures can implement an interface but they cannot inherit from another structure
c
Structure members cannot be declared as protected
d
A structure can be empty
correct answer b,c
Answer: Option (B) and Option (C)
8
Calculate the number of bytes a structure variable s occupies in the memory if it is defined as follows.
class abc
{
int i;
Decimal d;
}
struct sample
{
privateint x;
private Single y;
private trial z;
}
sample s =new sample();
a
24 bytes
b
8 bytes
c
16 bytes
d
12 bytes
correct answer d
Answer: Option (D)
9
When does a structure variable get destroyed?
a
When no reference refers to it,it will get garbage collected
b
Depends on whether it is created using new or without new operator
c
As variable goes out of the scope
d
Depends on either we free its memory using free() or delete()
correct answer c
Answer: Option (C)
10
Which of the following is the correct output for the C#.NET program code given below?