Skip to main content

Modern Programming Languages MCQs with Answers

Practice important Modern Programming Languages MCQs with answers and explanations.

Chapter: 32
Q641:
Which of the following is a feature of C# enumerations?
A. They are mutable
B. They are type-safe
C. They allow multiple values per item
D. They store only characters
Correct Answer: B
Chapter: 32
Q642:
Which operator is used to retrieve the string representation of an enumeration in C#?
A. ToString()
B. EnumToString()
C. GetEnumString()
D. ToEnumString()
Correct Answer: A
Chapter: 32
Q643:
In C#, which keyword is used to declare unsafe code?
A. unsafe
B. fixed
C. volatile
D. unsafe-block
Correct Answer: A
Chapter: 32
Q644:
What does C# use to manage memory allocation in managed code?
A. Garbage collector
B. Manual memory management
C. Direct memory access
D. Memory pointers
Correct Answer: A
Chapter: 32
Q645:
Which of the following is an advantage of using unmanaged code in C#?
A. Easier memory management
B. Better performance in real-time apps
C. More flexible array handling
D. Safer debugging
Correct Answer: B
Chapter: 32
Q646:
In C#, which of the following statements would lead to a compilation error when working with enumerations?
A. int i = (int)DAYS.Monday;
B. DAYS d = (DAYS)i;
C. int i = DAYS.Monday;
D. DAYS d = (int)DAYS.Monday;
Correct Answer: C
Chapter: 32
Q647:
What is a key difference between C# and C++ in terms of pointer usage?
A. C# pointers can only point to value types
B. C# pointers can be used for all types
C. C# does not support pointers
D. C# allows automatic pointer dereferencing
Correct Answer: A
Chapter: 32
Q648:
Which operator is used in C# to access elements of a struct via a pointer?
A. ->
B. &
C. *
D. $
Correct Answer: A
Chapter: 32
Q649:
Which keyword is used to declare a pointer in C#?
A. &
B. *
C. ->
D. unsafe
Correct Answer: B
Chapter: 32
Q650:
In C#, which type of code does not require explicit memory management?
A. Managed code
B. Unmanaged code
C. Unsafe code
D. Native code
Correct Answer: A
Chapter: 32
Q651:
Which of the following is not a type of array in C#?
A. Single-dimensional array
B. Rectangular array
C. Jagged array
D. Two-dimensional array
Correct Answer: D
Chapter: 32
Q652:
Which of the following would be used to prevent a pointer from pointing to an incorrect memory location due to garbage collection in C#?
A. fixed
B. unsafe
C. void
D. static
Correct Answer: A
Chapter: 32
Q653:
What would happen if you try to access a reference type using a pointer in C#?
A. Compilation error
B. Memory leak
C. Invalid pointer
D. Stack overflow
Correct Answer: A
Chapter: 32
Q654:
What is the syntax for declaring a single-dimensional array in C#?
A. int[] i = new int[5];
B. int i[] = new int[5];
C. int i = new int[5];
D. int[5] i = new int[];
Correct Answer: A
Chapter: 32
Q655:
In C#, which type of array allows each dimension to have a different length?
A. Jagged array
B. Rectangular array
C. Multidimensional array
D. Dynamic array
Correct Answer: A
Chapter: 32
Q656:
What does the 'unsafe' keyword allow in C#?
A. Declaring methods unsafe
B. Declaring unsafe pointers
C. Declaring managed memory
D. Declaring fixed-size arrays
Correct Answer: B
Chapter: 33
Q657:
In C#, Boolean values do not convert to which of the following?
A. Integer variables
B. Boolean expressions
C. Arithmetic operations
D. Characters
Correct Answer: A
Chapter: 33
Q658:
What is the result of the following C# code: int a = 5; x = a++ + --a; if evaluated left-to-right?
A. 8
B. 10
C. 5
D. 6
Correct Answer: B
Chapter: 33
Q659:
Which of the following loop types is used to iterate through the values contained by an object that implements the IEnumerable interface?
A. while
B. do-while
C. for
D. foreach
Correct Answer: D
Chapter: 33
Q660:
What is the correct syntax for a 'foreach' loop in C#?
A. foreach (variable1 in variable2) statement[s]
B. foreach (variable1) statement[s]
C. for (variable1 in variable2) statement[s]
D. foreach variable1 in variable2 statement[s]
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Modern Programming Languages

🚀 Start Quiz Now