Exercise: Structures
Questions for: Structures
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
Answer: B
No answer description is available. Let's discuss.
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:
Both ss and z will be created on the heap.
Answer: E
No answer description is available. Let's discuss.
Discuss About this Question.
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;
}
- Emp e(); e = new Emp();
- Emp e = new Emp;
- Emp e; e = new Emp;
- Emp e = new Emp();
- Emp e;
A:
1, 3
B:
2, 5
C:
4, 5
D:
1, 2, 4
Answer: C
No answer description is available. Let's discuss.
Discuss About this Question.
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;
Answer: A
No answer description is available. Let's discuss.
Discuss About this Question.
Which of the following will be the correct output for the C#.NET program given below?
namespace ExamAdept
{
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
Answer: C
No answer description is available. Let's discuss.
Discuss About this Question.
Ad Slot (Above Pagination)
Discuss About this Question.