Users Online
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Latest Articles
Articles Hierarchy
C# Questions & Answers ? Fundamentals of Preprocessors
C# Questions & Answers – Fundamentals of Preprocessors
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) &
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
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
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
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
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 the following C# code snippet?
-
#define pi
-
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Text;
-
using System.Threading.Tasks;
-
-
namespace ConsoleApplication13
-
{
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
#if (!pi)
-
Console.WriteLine("i");
-
#else
-
Console.WriteLine("pi not define");
-
#endif
-
Console.WriteLine("ok");
-
Console.ReadLine();
-
}
-
}
-
}
a)
i pi not define
b)
pi not define ok
c)
i ok
d) ok
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 the following C# code snippet?
-
#define DEBUG
-
#define MYTEST
-
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Text;
-
using System.Threading.Tasks;
-
-
namespace ConsoleApplication13
-
{
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
#if (DEBUG && !MYTEST)
-
Console.WriteLine("DEBUG is defined");
-
#elif (!DEBUG && MYTEST)
-
Console.WriteLine("MYTEST is defined");
-
#elif (DEBUG && MYTEST)
-
Console.WriteLine("DEBUG and MYTEST are defined");
-
#else
-
Console.WriteLine("DEBUG and MYTEST are not defined");
-
#endif
-
Console.ReadLine();
-
}
-
}
-
}
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
Explanation: None.
8. What will be the output of the following C# code snippet?
-
#define DEBUG
-
#undef DEBUG
-
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Text;
-
using System.Threading.Tasks;
-
-
namespace ConsoleApplication13
-
{
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
#if (DEBUG)
-
Console.WriteLine("DEBUG is defined");
-
#elif (!DEBUG && MYTEST)
-
Console.WriteLine("MYTEST is defined");
-
#elif (DEBUG && MYTEST)
-
Console.WriteLine("DEBUG and MYTEST are defined");
-
#else
-
Console.WriteLine("DEBUG and MYTEST are not defined");
-
#endif
-
Console.ReadLine();
-
}
-
}
-
}
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
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
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
Explanation: None.