logo
  • Home
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Contact

C# Multiple Choice Questions | MCQs | Quiz

C# Interview Questions and Answers
Pratice C# questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Integer Data Types
•   Floating Data Types
•   String Literals
•   Variables Initialization
•   Variables Scope & Lifetime
•   Expression Type Conversion
•   Arithmetic Operators
•   Logical Operators
•   Bit Wise Operators
•   IF Statements
•   Switch Statements
•   For Loop Statements
•   While Loop Statements
•   Do While Loop Statements
•   Continue & Goto statement
•   Class Fundamentals
•   Reference Variables
•   Methods in Class
•   Constructors in Class
•   Destructors in Class
•   Array & Initialization
•   Strings Basic Operation
•   String Class Description
•   Strings Comparison
•   Modifying Strings
•   Characters Operation
•   Private Access Modifier
•   Ref & Out Parameters
•   Variable Arguements
•   Polymorphism
•   Structures
•   Enumerations
•   Inheritance Fundamentals
•   Inheritance Implementation
•   Method Overloading
•   Method Overriding
•   Constructor Overloading
•   Abstract Class & Methods
•   Interfaces Introduction
•   Interfaces Implementation
•   Overloaded Operators
•   Recursion
•   Indexers Basics
•   Properties Basics
•   Properties & Its Application
•   Exception Handling Basics
•   Exception Implementation
•   Built In Exceptions
•   Detail Try & Catch
•   Attributes
•   Console I/O Operations
•   Reading Console Input
•   Writing Console Output
•   Stream Classes Basics
•   Byte Stream
•   Character Stream
•   Delegates Fundamentals
•   Detail Delegates
•   Generics Fundamentals
•   Generic Methods
•   LINQ Fundamentals
•   LINQ Operation & Query
•   Array Class Basics
•   Runtime Type
•   Reflections Basics
•   Collection Classes
•   Maths Class
•   C# Rounding Functions
•   Multi-threaded Programs - 1
•   Multi-threaded Programs - 2
•   Iterators
•   Namespaces Fundamentals
•   Preprocessor Fundamentals
•   Parameters Method
•   Networking Fundamentals
•   URI Class
•   Network Errors Handling
•   Type Interface
•   Unsafe Code & Pointers
•   Pointers Operation - 1
•   Pointers Operation - 2
•   Class Accessor Controls
•   String Formatting Basics
•   String Formatting - 1
•   String Formatting - 2

Best Reference Books

C# Books
« Prev Page
Next Page »

C# Questions & Answers – Pointers Operation – 1

Posted on September 11, 2013 by staff10

This section of our 1000+ C# MCQs focuses on operation on pointers in C# Programming Language.

1. What will be the output of the given code?

  1.  class UnsafeCode
  2.  {
  3.      unsafe static void Main()
  4.      {
  5.          int m = 10;
  6.          int *mptr = &m;
  7.          int **ptr = &mptr;
  8.          int n = 20;
  9.          int *nptr = &n;
  10.          int **prt = &nptr;
  11.          m = **prt + *nptr;
  12.          n = *mptr* **prt;
  13.          Console.WriteLine(n + " " + m);
  14.          Console.ReadLine();
  15.      }
  16.  }

a) 20 200
b) 40 200
c) 800 40
d) 40 800
View Answer

Answer: c
Explanation: None.
Output: 800 40

2. What will be the output of the code snippet?

  1.  unsafe static void Main()
  2.  {
  3.      int a = 5;
  4.      int b = 5;
  5.      int c = 5;
  6.      int*[] ptr = new int* [3];
  7.      ptr[0] = &a;
  8.      ptr[1] = &b;
  9.      ptr[2] = &c;
  10.      for (a = 0; a < 3; a++)
  11.      {
  12.          c += *ptr[a];
  13.          Console.WriteLine(c);
  14.      }
  15.      Console.ReadLine();
  16.  }

a) 5 10
b) 10 20
c) Compile time error
d) 5 10 20
View Answer

Answer: d
Explanation: None.
Output:5 10 20

3. What will be the output of the code snippet?

  1. class UnsafeCode
  2. {
  3.     unsafe static void Main()
  4.     {
  5.         int* ptrs = stackalloc int[3];
  6.         ptrs[0] = 1;
  7.         ptrs[1] = 2;
  8.         ptrs[2] = 3;
  9.         for (int i = 2; i >= 0; --i)
  10.         {
  11.             ptrs[i] = ptrs[i]* 3;
  12.             ptrs[i] = ptrs[i] + 4;
  13.             Console.WriteLine(ptrs[i]);
  14.         }
  15.         Console.ReadLine();
  16.     }
  17. }

a) 20, 10, 7
b) 13, 10, 7
c) 6, 9, 3
d) Compile time error
View Answer

Answer: b
Explanation: None.
Output: 13, 10, 7

4. Among the given pointers which of following cannot be incremented?
a) int
b) char
c) float
d) void
View Answer

Answer: d
Explanation: None.

5. A structure pointer points to __________
a) first member of structure
b) first two members of structure
c) whole structure
d) only to the last member of structure
View Answer

Answer: c
Explanation: None.

6. What will be the declaration of the variable ptr as the pointer to array of 6 floats?
a) float *ptr[6].
b) float [6]*ptr
c) float(*ptr)[6].
d) float(*ptr)(6).
View Answer

Answer: c
Explanation: None.

7. what will be the output of code snippet?

  1.  class UnsafeCode
  2.  {
  3.      unsafe static void Main()
  4.      {
  5.          char[] arr = { 'A', 'B', 'C', 'D', 'E' };
  6.          fixed (char* P = arr)
  7.          {
  8.              int i;
  9.              for (i = 0 ;i < 5 ;i++)
  10.              if (*P % 2 == 0)
  11.              ++*P;
  12.              else
  13.              (*P)++;
  14.              Console.WriteLine(arr);
  15.          }
  16.          Console.ReadLine();
  17.      }
  18.  }

a) ACCEE
b) FBCDE
c) BBDDF
d) BBCEE
View Answer

Answer: b
Explanation: None.
Output:FBCDE

8. What will be the output of given code snippet?

  1. class UnsafeCode
  2.  {
  3.      unsafe static void Main()
  4.      { 
  5.          int[] nums = new int[10];
  6.          Console.WriteLine("Index pointer like array.");
  7.          fixed (int* p = nums)
  8.          {
  9.              for (int i = 0 ;i <10 ;i++)
  10.              p[i] = i;
  11.              for (int i = 10 ;i >0 ;i--)
  12.              Console.WriteLine("p[{0}]: {1} ", i, p[i]);
  13.              Console.ReadLine();
  14.          }
  15.      }
  16.  }

a) p[10] :0, p[9] :9, p[8] :8…..p[1]:1
b) p[10] : 1, p[9] :2, p[8] :3…..p[1] :0
c) p[1] : 1, p[2] :2, p[3] :3…..p[10] :0
d) Compile time error
View Answer

Answer: a
Explanation: None.
Output:Index pointer like array:
p[10] :0, p[9] :9, p[8] :8…p[1]:1

9. What will be the output of the given code snippet?

  1.  class UnsafeCode
  2.  {
  3.      unsafe static void Main()
  4.      {
  5.          string str = "this is a test";
  6.  
  7.              fixed (char* p = str)
  8.             {
  9.                 for (int i = str.Length-1 ;p[i] != 0 ;i--)
  10.                 Console.Write(p[i]);
  11.             }
  12.         Console.ReadLine();
  13.     }
  14.  }

a) test a is this
b) compile time error
c) tset a si siht
d) run time error
View Answer

Answer: c
Explanation: Reversal of string using pointers.
Output:tset a si siht

10. What will be the output of given code snippet?

  1.  class UnsafeCode
  2.  {
  3.      unsafe static void Main()
  4.      {
  5.          int* p ;
  6.          int ch = 13*5;
  7.          p = &(ch);
  8.          Console.WriteLine(Convert.ToChar(*p));
  9.          if (*p == 'A')
  10.          Console.WriteLine(Convert.ToBoolean(1));
  11.          else
  12.          Console.WriteLine(Convert.ToBoolean(0));
  13.          Console.ReadLine();
  14.      }
  15.  }

a) 65 False
b) 65 1
c) A True
d) A 1
View Answer

Answer: c
Explanation: Convert.Tochar(*p) = A
Convert.ToBoolean(1) = True
Output: A
True

Sanfoundry Global Education & Learning Series – C# Programming Language.

Here’s the list of Best Reference Books in C# Programming Language.

To practice all features of C# programming language, here is complete set on 1000+ Multiple Choice Questions and Answers on C#.

« Prev Page - C# Questions & Answers – Unsafe code & Pointers Basics
» Next Page - C# Question & Answers – Pointers Operation – 2
« C# Questions & Answers – Unsafe code & Pointers Basics
C# Question & Answers – Pointers Operation – 2 »

Deep Dive @ Sanfoundry:

  1. C# Programming Examples on Functions
  2. Java Questions and Answers
  3. C# Questions and Answers
  4. Compilers Questions and Answers – Switch Case – 1
  5. C# Questions & Answers – Implementation of Exception Handling
  6. C# Questions & Answers – Basic Operation on Strings
  7. C# Questions & Answers – String Formatting – 2
  8. C# Program to Swap the Contents of two Numbers using Bitwise XOR Operation
  9. C# Question & Answers – Maths Class
  10. C# Questions & Answers – Operation with LINQ
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn | Facebook | Twitter | Google+

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
TOS & Privacy
Jobs
Bangalore Training
Online Training
SAN Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry