Knowee
Questions
Features
Study Tools

Preprocessor directives are lines included in the code preceded by a hash sign (#). These lines are directives for the preprocessor. The preprocessor examines the code before actual compilation of code begins and resolves all these directives before any code is actually generated by regular statements.#define INF 10000000if( val == INF) {//Do something}After the preprocessor has replaced the directives, the code will beif( val == 10000000) { //Here INF is replaced by the value with which it's defined.//Do something}You can also define function macros which have parameters.#define add(a, b) a + bint x = add(a, b);The second statement after the preprocessor has replaced the directives will be:int x = a + b;To know more about preprocessor directives, you can go to this linkYou're spending your afternoon at a local school, teaching kids how to code. You give them a simple task: find the difference between the maximum and minimum values in an array of integers.After a few hours, they came up with some promising source code. Unfortunately, it doesn't compile! Since you don't want to discourage them, you decide to make their code work without modifying it by adding preprocessor macros.Review the locked stub code in your editor and add the preprocessor macros necessary to make the code work.Input FormatThe first line contains an integer, , denoting the size of the array.The second line contains space-separated integers, , describing the elements in the array.ConstraintsOutput FormatYou are not responsible for printing any output to stdout. Once the necessary preprocessor macros are written, the locked code in your editor will print a line that says , where is the difference between the maximum and minimum values in the array.Sample Input532 332 -23 -154 65Sample OutputResult = 486

Question

Preprocessor directives are lines included in the code preceded by a hash sign (#). These lines are directives for the preprocessor. The preprocessor examines the code before actual compilation of code begins and resolves all these directives before any code is actually generated by regular statements.#define INF 10000000if( val == INF) {//Do something}After the preprocessor has replaced the directives, the code will beif( val == 10000000) { //Here INF is replaced by the value with which it's defined.//Do something}You can also define function macros which have parameters.#define add(a, b) a + bint x = add(a, b);The second statement after the preprocessor has replaced the directives will be:int x = a + b;To know more about preprocessor directives, you can go to this linkYou're spending your afternoon at a local school, teaching kids how to code. You give them a simple task: find the difference between the maximum and minimum values in an array of integers.After a few hours, they came up with some promising source code. Unfortunately, it doesn't compile! Since you don't want to discourage them, you decide to make their code work without modifying it by adding preprocessor macros.Review the locked stub code in your editor and add the preprocessor macros necessary to make the code work.Input FormatThe first line contains an integer, , denoting the size of the array.The second line contains space-separated integers, , describing the elements in the array.ConstraintsOutput FormatYou are not responsible for printing any output to stdout. Once the necessary preprocessor macros are written, the locked code in your editor will print a line that says , where is the difference between the maximum and minimum values in the array.Sample Input532 332 -23 -154 65Sample OutputResult = 486

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The task requires you to add preprocessor directives to a given code to make it work. The code is supposed to find the difference between the maximum and minimum values in an array of integers.

The preprocessor directives you need to add are:

#define INF 10000000
#define FUNCTION(name,operator) void name(int &current, int candidate) {!(current operator candidate) ? current = candidate : false;}
#define io(v) cin >> v
#define toStr(str) #str
#define foreach(v, i) for (int i = 0; i < v.size(); ++i)
#define maximum(a) *max_element(a.begin(), a.end())
#define minimum(a) *min_element(a.begin(), a.end())

The FUNCTION macro defines a function that updates the current value if the candidate value satisfies the operator condition. The io macro is a shortcut for input operation. The toStr macro converts the argument into a string. The foreach macro is a shortcut for a for loop. The maximum and minimum macros find the maximum and minimum element in an array respectively.

After adding these preprocessor directives, the code will work as expected and print the difference between the maximum and minimum values in the array.

This problem has been solved

Similar Questions

Preprocessor directives are lines included in the code preceded by a hash sign (#). These lines are directives for the preprocessor. The preprocessor examines the code before actual compilation of code begins and resolves all these directives before any code is actually generated by regular statements.#define INF 10000000if( val == INF) {//Do something}After the preprocessor has replaced the directives, the code will beif( val == 10000000) { //Here INF is replaced by the value with which it's defined.//Do something}You can also define function macros which have parameters.#define add(a, b) a + bint x = add(a, b);The second statement after the preprocessor has replaced the directives will be:int x = a + b;To know more about preprocessor directives, you can go to this linkYou're spending your afternoon at a local school, teaching kids how to code. You give them a simple task: find the difference between the maximum and minimum values in an array of integers.After a few hours, they came up with some promising source code. Unfortunately, it doesn't compile! Since you don't want to discourage them, you decide to make their code work without modifying it by adding preprocessor macros.Review the locked stub code in your editor and add the preprocessor macros necessary to make the code work.Input FormatThe first line contains an integer, , denoting the size of the array.The second line contains space-separated integers, , describing the elements in the array.ConstraintsOutput FormatYou are not responsible for printing any output to stdout. Once the necessary preprocessor macros are written, the locked code in your editor will print a line that says , where is the difference between the maximum and minimum values in the array.Sample Input532 332 -23 -154 65Sample OutputResult = 486

what is Preprocessors and Preprocessors directives.

What does the hash ( # ) sign mean in PHP?It indicates variable declarationIt indicates line that are commented outIt indicates end of the statementIt indicates function declaration

Which is not a preprocessor directive of C-language?

Let us try to understand the basic structure of a simple C program.The C source code given below prints "Hello!" to the console.#include <stdio.h>void main() { printf("Hello!");}The first line of the program #include <stdio.h> has three parts:The # character is called the preprocessor directiveinclude is a commandstdio.h is the name of the header file that we are trying to includeA header file usually contains useful predefined functions.A preprocessor directive is executed before the compilation is done. We shall learn more about the preprocessor in later sections.Note: Preprocessor directives are lines included in a program that begin with the character #, which make them different from a typical source code text. They are invoked by the compiler to process some programs before compilation.The #include <stdio.h> preprocessor command includes the contents of the file stdio.h into our program, which makes the different I/O functions like printf(),scanf(), etc.. available for use.Click on Live Demo to know about the preprocessor command #include.The second line of the program void main() contains two parts:void in English means empty or nothing. In our program's context, void is the return type. It means that the function main() returns nothing.main() is a function (also called a subroutine) which is called by the operating system. main() is the starting point of execution in any C program.printf() is a function which is used to print the text specified within double-quotes to the standard output device ( i.e, Console/Monitor).The executable statements, which in this case, is a call to printf() function, must be enclosed within an open brace { and a close brace }.Select all the correct statements from the given statements:#include is a preprocessor command.Header files contain functions that are automatically generated by machines.C program can run without main() function.printf("CodeTantra"); statement prints CodeTantra on the console.

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.