C# Interview Questions - 30 | Snaprecruit.com

C# Interview Questions - 30 | Snaprecruit.com

C SHARP interview questions part 30

C SHARP interview questions part 30

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. What will be the output of the given set of code? static void Main(string[] args) { int a = 5; int b = 0, c = 0; method (a, ref b, ref c); Console.WriteLine(b + " " + c); Console.ReadLine(); } static int method(int x, int p, ref int k) { p = x + x * x; k = x * x + p; return 0; }

Correct Answer is : 24

2. Keyword used to define call by reference parameter in C# .NET?

Correct Answer is : 1

3. Select the correct match of parameter declaration: static Void main(string[] args) { int a = 5; int b = 6; float c = 7.2f; math (ref a, ref b, ref c); Console.WriteLine(a + " " + b + " " + c); } static int math(/*add parameter declaration */) { a += b; b *= (int)c; c += a * b; return 0; }

Correct Answer is : 48

4. Which statement is/are correct?

Correct Answer is : 72

5. The method in which large or variable number of arguments are handled is known as:

Correct Answer is : Stack

6. The modifiers used to define an array of parameters or list of arguments:

Correct Answer is : Runtime Error

7. What will be the output for the given set of code ? static void Main(string[] args) { object[] a = {" 1 ", 4.0f, " harsh "}; fun(a); Console.ReadLine(); } static void fun(params object[] b) { for (int i = 0; i < b.Length - 1; i++) Console.WriteLine(b[i] + " "); }

Correct Answer is : 12

8. What will be the output of the set of code? static void Main(string[] args){ int [] a = {1, 2, 3, 4, 5}; fun(a); Console.ReadLine();}static void fun(params int[] b ){ int[] k = { 3, 4, 7, 8,'\0' }; for (int i = 0; i < b.Length; i++) { b[i] = b[i] + k[i] ; Console.WriteLine( b[i] + " "); }}

Correct Answer is : ref

9. What will be the output the of given set of code? static void Main(string[] args) { int [] a = {1, 2, 3, 4, 5}; fun(a); Console.ReadLine(); } static void fun(params int[] b ) { for (int i = 0; i < b.Length; i++) { b[i] = b[i] * 5 ; Console.WriteLine(b[i] + ""); } }

Correct Answer is : 25

10. What will be the output of the given set of code? static void Main(string[] args) { int[] a = { 2, 21, 34, 46, 85, 88, 90}; fun(a); Console.WriteLine(a + " "); Console.ReadLine(); } static void fun(params int [] b ) { int [] c = { 1, 2, 3, 4, 5, 6, 7}; int i ; for (i = 0 ;i < b.Length ;i++) if (b[i] % 2 == 0) { c[i] = b[i]; } Console.WriteLine("even numbers are:"); for (i = 0 ;i <= b.Length ;i++) { Console.WriteLine(c[i]); } }

Correct Answer is : 6 7 8 9 10

11. Select the correct declaration of the defining array of parameters:

Correct Answer is : Result before swap is: 10 20

12. What will be the output of the given set of code? static void Main(string[] args) { int[] x = { 80, 82, 65, 72, 83, 67 }; fun(x); Console.ReadLine(); } static void fun(params int [] b ) { int i; for (i = 5; i >=0 ; i--) { Console.WriteLine(Convert.ToChar(b[i])); } }

Correct Answer is : numbers are : 3 5 7 9 11

13. What will be the output of the given set of code? static void Main(string[] args) { int[] x = {65, 66, 67, 68, 69, 70}; fun(x); Console.ReadLine(); } static void fun(params int[] b ) { int i; for (i = 5; i > 0 ; i--) { b[i] = b[i] + 32; Console.WriteLine(Convert.ToChar(b[i])); } }

Correct Answer is : References can be called recursively

14. Select the output for the following set of code : static void Main(string[] args) { int i, j; for (i = 1; i <= 3; i++) { j = 1; while (i % j == 2) { j++; } Console.WriteLine(i + " " + j); } Console.ReadLine(); }

Correct Answer is : ‘=’ operator is used to assign values from one variable to another variable

15. Select the output for the following set of code: static void Main(string[] args) { float s = 0.1f; while (s <= 0.5f) { ++s; Console.WriteLine(s); } Console.ReadLine(); }

Correct Answer is : It is not zero

16. Select the output for the following set of Code: static void Main(string[] args) { int i; i = 0; while (i++ < 5) { Console.WriteLine(i); } Console.WriteLine("\n"); i = 0; while ( ++i < 5) { Console.WriteLine(i); } Console.ReadLine();}

Correct Answer is : 4 0

17. Select the output for the following set of Code: static void Main(string[] args) { int x = 0; while (x < 20) { while (x < 10) { if (x % 2 == 0) { Console.WriteLine(x); } x++; } } Console.ReadLine(); }

Correct Answer is : int

18. Predict the output for the following set of code : static void Main(string[] args) { int x; x = Convert.ToInt32(Console.ReadLine()); int c = 1; while (c <= x) { if (c % 2 == 0) { Console.WriteLine("Execute While " + c + "\t" + "time"); } c++; } Console.ReadLine(); }for x = 8.

Correct Answer is : Compile time error

19. Select the output for the following set of Code: static void Main(string[] args) { int n, r; n = Convert.ToInt32(Console.ReadLine()); while (n > 0) { r = n % 10; n = n / 10; Console.WriteLine(+r); } Console.ReadLine(); } for n = 5432.

Correct Answer is : 32 2 8

20. Select the output for the following set of Code: static void Main(string[] args) { float i = 1.0f, j = 0.05f; while (i < 2.0f && j <= 2.0f) { Console.WriteLine(i++ - ++j); } Console.ReadLine(); }

Correct Answer is : “Line 1 – a is greater to b”

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon