C# Interview Questions - 19 | Snaprecruit.com

C# Interview Questions - 19 | Snaprecruit.com

C SHARP interview questions part 19

C SHARP interview questions part 19

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 code snippet? unsafe static void Main() { int a = 5; int b = 5; int c = 5; int*[] ptr = new int* [3]; ptr[0] = &a; ptr[1] = &b; ptr[2] = &c; for (a = 0; a < 3; a++) { c += *ptr[a]; Console.WriteLine(c); } Console.ReadLine(); }

Correct Answer is : this

2. What will be the output of the code snippet? class UnsafeCode{ unsafe static void Main() { int* ptrs = stackalloc int[3]; ptrs[0] = 1; ptrs[1] = 2; ptrs[2] = 3; for (int i = 2; i >= 0; --i) { ptrs[i] = ptrs[i]* 3; ptrs[i] = ptrs[i] + 4; Console.WriteLine(ptrs[i]); } Console.ReadLine(); }}

Correct Answer is : access

3. Among the given pointers which of following cannot be incremented?

Correct Answer is : All of the mentioned

4. A structure pointer points to __________

Correct Answer is : class student

5. What will be the declaration of the variable ptr as the pointer to array of 6 floats?

Correct Answer is : All of the mentioned

6. what will be the output of code snippet? class UnsafeCode { unsafe static void Main() { char[] arr = { 'A', 'B', 'C', 'D', 'E' }; fixed (char* P = arr) { int i; for (i = 0 ;i < 5 ;i++) if (*P % 2 == 0) ++*P; else (*P)++; Console.WriteLine(arr); } Console.ReadLine(); } }

Correct Answer is : All of the mentioned

7. What will be the output of given code snippet? class UnsafeCode { unsafe static void Main() { int[] nums = new int[10]; Console.WriteLine("Index pointer like array."); fixed (int* p = nums) { for (int i = 0 ;i <10 ;i++) p[i] = i; for (int i = 10 ;i >0 ;i--) Console.WriteLine("p[{0}]: {1} ", i, p[i]); Console.ReadLine(); } } }

Correct Answer is : group g = new group();

8. What will be the output of the given code snippet? class UnsafeCode { unsafe static void Main() { string str = "this is a test";  fixed (char* p = str) { for (int i = str.Length-1 ;p[i] != 0 ;i--) Console.Write(p[i]); } Console.ReadLine(); } }

Correct Answer is : A class

9. What will be the output of given code snippet? class UnsafeCode { unsafe static void Main() { int* p ; int ch = 13*5; p = &(ch); Console.WriteLine(Convert.ToChar(*p)); if (*p == 'A') Console.WriteLine(Convert.ToBoolean(1)); else Console.WriteLine(Convert.ToBoolean(0)); Console.ReadLine(); } }

Correct Answer is : Run time error

10. What will be the output of given code snippet? class UnsafeCode{ struct MyStruct { public int a; public int b; public int Sum() { return a * b; } } unsafe static void Main() { MyStruct o = new MyStruct(); MyStruct* p; p = &o; p->a = 10; p->b = 20; Console.WriteLine("Value is " + p->Sum()); Console.ReadLine(); }}

Correct Answer is : operator

11. What will be the output of given code snippet? class UnsafeCode{ struct MyStruct { public int a; public int b; public int Sum() { return a / b; } } unsafe static void Main() { MyStruct o = new MyStruct(); MyStruct* p; p = &o; p->a = 60; p->b = 15; int c = 30; Console.WriteLine("Value is : " + p->Sum()*c); Console.ReadLine(); }}

Correct Answer is : The conditional logical operators cannot be overloaded

12. What will be the output of given code snippet? class UnsafeCode{ unsafe static void Main() { int[] nums = new int[10]; fixed (int* p = &nums[0], p2 = nums) { if (p == p2) Console.WriteLine("p and p2 point to same address."); Console.ReadLine(); } }}

Correct Answer is : ‘<<‘ < ‘&’ < ‘%’ < ‘-‘ < ‘/’ < ‘+’

13. What will be the output of given code snippet? class UnsafeCode{ static void Main() { int? count = null; int? result = null; int incr = 10; result = count + incr; if (result.HasValue) Console.WriteLine("result has this value: " + result.Value); else Console.WriteLine("result has no value"); Console.ReadLine(); }}

Correct Answer is : #ERROR!

14. What will be the output of given code snippet? class UnsafeCode{ static void Main() { int count = 100; int? result = null; int incr = 10; result = count + incr; if (result.HasValue) Console.WriteLine("result has this value: " + result.Value); else Console.WriteLine("result has no value"); Console.ReadLine(); }}

Correct Answer is : All of the mentioned

15. What does the following code depicts? 1. System.Nullable count; 2. bool? done;

Correct Answer is : public static sample operator +(int a, int b)

16. Which operator is commonly used to find the size of the type of C#?

Correct Answer is : Each property consists of accessor as get and set

17. What will be the output of given code snippet? unsafe struct FixedBankRecord { public fixed byte Name[80]; public double Balance; public long ID; } class UnsafeCode { unsafe static void Main() { Console.WriteLine("Size of FixedBankRecord is " + sizeof(FixedBankRecord)); Console.ReadLine(); } }

Correct Answer is : All of the mentioned

18. What will be the output of given code snippet? class UnsafeCode{ unsafe static void Main() { int* ptrs = stackalloc int[3]; ptrs[0] = 1; ptrs[1] = 2; ptrs[2] = 3; for (int i = 2; i >=0; i--) Console.WriteLine(ptrs[i]); Console.ReadLine(); }}

Correct Answer is : All of the mentioned

19. The capability of an object in Csharp to take number of different forms and hence display behaviour as according is known as:

Correct Answer is : All of the mentioned

20. Select the output for the given set of code? public class sample { public static int x = 100; public static int y = 150;  } public class newspaper :sample { new public static int x = 1000; static void Main(string[] args) { console.writeline(sample.x + " " + sample.y + " " + x); } }

Correct Answer is : All of the mentioned

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon