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 – Fundamentals of Preprocessors

Posted on September 11, 2013 by staff10

This section of our 1000+ C# MCQs focuses on fundamentals of preprocessors in C# Programming Language.

1. Choose the symbol which begins a preprocessor directive in C#.NET?
a) #
b) **
c) *
d) &
View Answer

Answer: a
Explanation: #define, #elif, #else etc.

2. What is meant by preprocessor directive in C#.NET?
a) a form of command which are interpreted by the compiler
b) a form of macros like in c and c++ not exactly same to them , separately designed for C#.NET
c) always begins with a ‘#’ character occupies separate line of source of code
d) all of the mentioned
View Answer

Answer: d
Explanation: Preprocessor directives are commands that are interpreted by the compiler and affect the output or behavior of the build process. The C# compiler does not have a separate preprocessor, like C and C++ we cannot use these directives to create macros. Preprocessing directives are top lines in our program that start with ‘#’. The ‘#’ is followed by an identifier that is the directive name.

3. What is meant by preprocessor directive #define?
a) defines a character sequence
b) helps in determining existence and non existence of a symbol
c) can be used to create function like macros as in C/C++
d) all of the mentioned
View Answer

Answer: a
Explanation: The #define directive defines a character sequence called a symbol. The existence or nonexistence of a symbol can be determined by #if or #elif and is used to control compilation. #define which supports creation of function like macros in c/c++ does not support the same in C#.

4. Select the defined preprocessor in C#.NET?
a) #define
b) #elif
c) #else
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

5. What does preprocessor directive #if and #endif explains?
a) Enables compilation of sequence of code on condition basis
b) Express results into true or false on evaluation of condition
c) If expression following #if is true then code that is between #if and #endif is compiled otherwise skipped
d) All of the mentioned
View Answer

Answer: d
Explanation: The #if and #endif directives enable conditional compilation of a sequence of code based upon whether an expression involving one or more symbols evaluates to true. A symbol is true if it has been defined. It is false otherwise.If the expression following #if is true, the code that is between it and #endif is compiled.Otherwise, the intervening code is skipped. The #endif directive marks the end of an #if block.

6. What will be the output of following code snippet?

  1.  #define pi 
  2.  using System;
  3.  using System.Collections.Generic;
  4.  using System.Linq;
  5.  using System.Text;
  6.  using System.Threading.Tasks;
  7.  
  8.  namespace ConsoleApplication13
  9. {
  10.     class Program
  11.     {   
  12.         static void Main(string[] args)
  13.         {
  14.             #if (!pi) 
  15.             Console.WriteLine("i");
  16.             #else 
  17.             Console.WriteLine("pi not define");
  18.             #endif
  19.             Console.WriteLine("ok");
  20.             Console.ReadLine();
  21.        }
  22.    }
  23. }

a) i
pi not define
b) pi not define
ok
c) i
ok
d) ok
View Answer

Answer: b
Explanation: The defined symbol ‘pi’ when compared as per ‘if’ condition, hence the outcome is false which results in skip of statement and hence executes statement after #else and finally the end statement after #endif.
Output: pi not define
ok

7. What will be the output of following code snippet?

  1. #define DEBUG 
  2. #define MYTEST
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace ConsoleApplication13
  10. {
  11.     class Program
  12.     {   
  13.         static void Main(string[] args)
  14.         {
  15.             #if (DEBUG && !MYTEST)
  16.             Console.WriteLine("DEBUG is defined");
  17.             #elif (!DEBUG && MYTEST)
  18.             Console.WriteLine("MYTEST is defined");
  19.             #elif (DEBUG && MYTEST)
  20.             Console.WriteLine("DEBUG and MYTEST are defined");
  21.             #else
  22.             Console.WriteLine("DEBUG and MYTEST are not defined");
  23.             #endif
  24.             Console.ReadLine();
  25.         }
  26.     }
  27. }

a) DEBUG is defined
MYTEST is defined
b) MYTEST is defined
DEBUG and MYTEST are defined
c) DEBUG and MYTEST are not defined
MYTEST is defined
d) DEBUG and MYTEST are defined
View Answer

Answer: d
Explanation: None.

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

  1. #define DEBUG 
  2. #undef DEBUG
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace ConsoleApplication13
  10. {
  11.     class Program
  12.     {   
  13.         static void Main(string[] args)
  14.         {
  15.             #if (DEBUG)
  16.             Console.WriteLine("DEBUG is defined");
  17.             #elif (!DEBUG && MYTEST)
  18.             Console.WriteLine("MYTEST is defined");
  19.             #elif (DEBUG && MYTEST)
  20.             Console.WriteLine("DEBUG and MYTEST are defined");
  21.             #else
  22.             Console.WriteLine("DEBUG and MYTEST are not defined");
  23.             #endif
  24.             Console.ReadLine();
  25.        }
  26.    }
  27. }

a) DEBUG is defined
DEBUG and MYTEST are not defined
b) DEBUG and MYTEST are not defined
c) MYTEST is defined
DEBUG and MYTEST are not defined
d) DEBUG is defined
View Answer

Answer: b
Explanation: #undef lets to undefine a symbol such that by using the symbol as the expression in a #if directive, the expression will evaluate to false i.e the symbol will be undefined in nature.
Output: DEBUG and MYTEST are not defined

9. Which preprocessor directive among the following forces the compiler to stop the compilation?
a) #warning
b) #endregion
c) #undef
d) #error
View Answer

Answer: d
Explanation: The #error directive forces the compiler to stop compilation. It is used for debugging. The general form of the #error directive is #error error-message. When the #error directive is encountered, the error message is displayed.

10. Which among the following is not a preprocessor directive?
a) #ifdef
b) #pragma
c) #Or
d) #undef
View Answer

Answer: c
Explanation: None.

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 – Fundamentals of Namespaces
» Next Page - C# Questions & Answers – Method with Parameters
« C# Questions & Answers – Fundamentals of Namespaces
C# Questions & Answers – Method with Parameters »

Deep Dive @ Sanfoundry:

  1. C# Programming Examples on Delegates
  2. C Questions and Answers
  3. Compilers Questions and Answers
  4. C Tutorials
  5. C# Programming Examples on Functions
  6. C# Questions & Answers – Fundamentals of Class
  7. C# Questions & Answers – Fundamentals of Exception Handling
  8. C Programming Questions and Answers – Conditional Inclusion – 1
  9. Explains Preprocessor Directives and their Uses in C Program
  10. What are Nested Directives in C
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