C MCQ Questions and Answers on Preprocessor Directives 1

Image
C MCQ Questions and Answers

Study C MCQ Questions and Answers on Preprocessor Directives. Easily attend technical job interviews with these Mulitple Choice Questions.

Go through C Theory Notes on Preprocessor Directives before studying questions.



1) What are the types of C Preprocessor Directives.?
A) Macros
B) Conditional Compilation
C) File Inclusion
D) All the above
Answer [=]
D
2) Processor Directive in C language starts with.?
A) $ symbol (DOLLAR)
B) @ symbol (At The Rate)
C) & symbol (Ampersand)
D) # symbol (HASH)
Answer [=]
D
Explanation:

eg. #include<stdio.h>

3) Preprocessor in C language works on.?
A) DOTC file (.c)
B) DOTEXE file (.exe)
C) DOTH file (.h)
D) DOTCP file (.cp)
Answer [=]
A
Explanation:

.C file is also called Source Code file.

4) What is the another name for .C file.?
A) Executable code
B) Source Code
C) Distributable Code
D) Macro code
Answer [=]
B
5) What is the keyword used to define a C macro.?
A) def
B) definition
C) define
D) defy
Answer [=]
C
Explanation:

#define PI 3.1428

6) What is the output of C program with #define.?
#define CVV 156
int main()
{
    int a=10;
    a = a*CVV;
    printf("CVV=%d",a);
    return 0;
}
A) 0
B) 1560
C) 1560
D) Compiler error
Answer [=]
C
Explanation:

During expansion of source code, a=a*CVV is replaced with a=a*156. #define is used to declare global constants.

7) What is the C keyword used to create global Constants.?
A) constant
B) definition
C) def
D) define
Answer [=]
D
Explanation:

#define KM 1.6



8) Choose a correct C statement about #define statement.?
#define CVV 156
A) CVV is called Macro Expansion. 156 is called Macro Template.
B) CVV is called Macro Expansion. 156 is also called Macro Expansion.
C) CVV is called Macro Template. 156 is called Macro Expansion.
D) None of the above
Answer [=]
C
9) What is the output file generated after processing a .C file.?
A) .h file
B) .exe file
C) .cp file
D) .bak file
Answer [=]
B
Explanation:

Yes. C program is converted to an executable file for distribution to outside world instead of sharing your original source code which may be copy righted logic.

10) How do you safeguard your .C file code from copying by outside developers or world.?
A) Encrypt a C file and share
B) Obfuscate a C file and share
C) Scramble a C file and share
D) Convert to Exe and share.
Answer [=]
D
11) What is the output of C program with macros.?
#define ERRMSG printf("Some error.");
int main()
{
    printf("JAR.");
    ERRMSG;
    return 0;
}
A) JAR.
B) JAR.ERRMSG
C) JAR.Some error.
D) Compiler error
Answer [=]
C
Explanation:

In place of ERRMSG corresponding macro expansion is substituted blindly.

12) What is the output of C program with macros.?
#define ERRMSG(a) printf("Error=%d",a);
int main()
{
    ERRMSG(10);
    return 0;
}
A) ERRMSG(10)
B) Error=
C) Error=10
D) Compiler error
Answer [=]
C
Explanation:

Inside main the statment printf("Error=%d",10) is substituted.

printf("Error=%d",10);
13) What is the output of C program.?
#define LOGIC(a,b) (a==b)
int main()
{
    if(LOGIC(5,5))
    {
        printf("SAME ");
    }
    return 0;
}
A) SAME
B) LOGIC(5,5)
C) 5==5
D) Compiler error
Answer [=]
A
Explanation:

LOGIC(5,5) is replaced by (5==5) with outer paranthesis.

14) How do you separate a multiline macro in C language.?
A) Using * operator
B) Using % operator
C) Using \ operator
D) Using + operator
Answer [=]
C
Explanation:
#define LOOP(a) while(a>0) \
{printf("%d ",a);}


15) What is the output of C program.?
#define LOOP(a) for(int i=1;i<=a;i++) \
{printf("%d ",i);}
int main()
{
    LOOP(5);
    return 0;
}
A) 5
B) 5 5 5 5 5
C) 1 2 3 4 5
D) Compiler error
Answer [=]
D
Explanation:

5 in LOOP(5) will be a condition for the FOR loop starting from i=1.

16) What is the output of C program.?
#define TANK(a) a*10+2
int main()
{
    int a = TANK(2)*2;
    printf("%d",a);
    return 0;
}
A) 44
B) 22
C) 24
D) Compiler error
Answer [=]
C
Explanation:

TANK(2)*2 is replaced by 2*20+2*2. It gives only 24. Remember, you should have put (a*10+2) paranthesis TANK definition to get expected results.

17) What is the file extension of expanded source code of .C file after preprocessing.?
A) .e file
B) .h file
C) .l file
D) .p file
Answer [=]
C
Explanation:

def.c is converted into def.l file.

18) What is the command to preprocess a C file manually.?
A) pp abc.c
B) cpp abc.c
C) exp abc.c
D) op abc.c
Answer [=]
B
Explanation:

cpp refers to C Pre Processor.

cpp abc.c
19) Choose a correct statement about C Macro.?
A) Macro template(eg. PI or function) will be replaced by Macro Expansion(3.1428) as many number of times as it appears in the C program increasing Source Code size in bytes.
B) Macros increase program speed when compared to functions.
C) Functions use less memory as the program code is written and placed only one place in source code. Macros put function code everywhere it is called again and again.
D) All the above
Answer [=]
D
20) What is the C Preprocessor directive to be used to add a header file or any file to existing C program.?
A) #add
B) #present
C) #include
D) $include
Answer [=]
C
Explanation:

#include<stdio.h>