gs gs108 Classes - Reference Variables and Assignment - Quiz No.1
gs gs108 CSharp Quiz
This quiz belongs to book/course code gs gs108 CSharp of gs organization. We have 110 quizzes available related to the book/course CSharp. This quiz has a total of 10 multiple choice questions (MCQs) to prepare and belongs to topic Classes. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
Question 3: What will be the output of the following C# code?
static void Main(string[] args) { int[] arr = new int[] {1, 2, 3, 4, 5}; fun1(ref arr); Console.ReadLine(); } static void fun1(ref int[] array) { for (int i = 0; i < array.Length; i++) { array[i] = array[i] + 5; Console.WriteLine(array[i] + " "); } }
6 7 8 9 10
15 17 8 8 20
15 17 8 29 20
Syntax error while passing reference of array variable
Question 4: What will be the output of the following C# code?
static void Main(string[] args) { int a = 10 , b = 20; Console.WriteLine("Result before swap is: "+ a +" "+b); swap(ref a, ref b); Console.ReadLine(); } static void swap(ref int i, ref int j) { int t; t = i; i = j; j = t; Console.WriteLine("Result after swap is:"+ i +" "+j); }
Result before swap is: 20 10 Result after swap is: 20 10
Result before swap is: 10 20 Result after swap is:20 10
Result before swap is: 10 20 Result after swap is:10 20
Result before swap is: 20 10 Result after swap is:10 20
Question 5: What will be the output of the following C# code?
static void Main(string[] args) { int []a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; func(ref a); Console.ReadLine(); } static void func(ref int[] x) { Console.WriteLine(" numbers are:"); for (int i = 0; i < x.Length; i++) { if (x[i] % 2 == 0) { x[i] = x[i] + 1; Console.WriteLine(x[i]); } } }
numbers are : 2 4 6 8 10
numbers are : 3 5 7 9 11
numbers are : 2 3 4 5 6
none of the mentioned
Question 6: Select the wrong statement about 'ref' keyword in C#?
References can be called recursively
The 'ref' keyword causes arguments to be passed by reference
When 'ref' are used, any changes made to parameters in method will be reflected in variable when control is passed back to calling method
All of the mentioned
Question 7: Select correct differences between '=' and '==' in C#.
'==' operator is used to assign values from one variable to another variable '=' operator is used to compare value between two variables
'=' operator is used to assign values from one variable to another variable '==' operator is used to compare value between two variables
No difference between both operators
None of the mentioned
Question 8: What will be the output of the following C# code?
static void Main(string[] args) { int X = 0; if (Convert.ToBoolean(X = 0)) Console.WriteLine("It is zero"); else Console.WriteLine("It is not zero"); Console.ReadLine(); }
It is zero
It is not zero
Infinite loop
None of the mentioned