Home Subjects C# Programming Basics & Syntax

C# Programming
Basics & Syntax

C# and .NET for campus placement

15 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–15 of 15
Topics in C# Programming
Q.11 Hard Basics & Syntax
What is the difference between 'struct' and 'class' in C# regarding memory allocation?
A Both are allocated on the heap
B Both are allocated on the stack
C struct is allocated on the stack, class on the heap
D struct is allocated on the heap, class on the stack
Correct Answer:  C. struct is allocated on the stack, class on the heap
EXPLANATION

Value types (struct) are allocated on the stack, while reference types (class) are allocated on the heap.

Test
Q.12 Hard Basics & Syntax
Consider: int[] arr = {1, 2, 3}; What happens when you try to resize it using Array.Resize(ref arr, 5)?
A Throws exception
B Creates new array with 5 elements, preserving first 3 values
C Returns null
D Changes original array size
Correct Answer:  B. Creates new array with 5 elements, preserving first 3 values
EXPLANATION

Array.Resize() creates a new array of specified size and copies elements from the original array using the ref parameter.

Test
Q.13 Hard Basics & Syntax
Which of the following is NOT a valid C# data type?
A sbyte
B uint
C float32
D decimal
Correct Answer:  C. float32
EXPLANATION

C# has float (4 bytes) and double (8 bytes), but not float32. sbyte, uint, and decimal are valid types.

Test
Q.14 Hard Basics & Syntax
Which of the following statements about structs and classes in C# is TRUE?
A Structs are reference types, classes are value types
B Structs are value types, classes are reference types
C Both are reference types
D Both are value types
Correct Answer:  B. Structs are value types, classes are reference types
EXPLANATION

In C#, structs are value types (stored on stack) while classes are reference types (stored on heap). This is a fundamental difference between the two.

Test
Q.15 Hard Basics & Syntax
Consider the following code. What will be the output?
int x = 10;
int y = 20;
int z = x++ + ++y;
Console.WriteLine(x + " " + y + " " + z);
A 10 20 30
B 11 21 31
C 11 21 30
D 10 21 31
Correct Answer:  B. 11 21 31
EXPLANATION

x++ returns 10 then increments x to 11. ++y increments y to 21 then returns 21. z = 10 + 21 = 31. Final output: 11 21 31

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips