Question

Question 2.   Explain preprocessor directives in C. Describe Error and pragma directives and write code snippets....

Question 2.

  Explain preprocessor directives in C.

  1. Describe Error and pragma directives and write code snippets.
  2. Describe define, and undef, directives.
  3. Write the code which shows if constant “VALUE” is not defined then define it and replace its value to 5 on runtime. Display the value of x.

int x = VALUE;

Homework Answers

Answer #1

1)Preprocessor Directives:These begin with # symbol.These directives normally used to include the header files such as stdio.h,stdlib.h,math.h,string.h

eg:#include<stdio.h>

#include<math.h>

2)#error directive will print an implementation-dependent message including the tokens specified in the directive.

#pragma directive tokens are a series of characters that gives a specific compiler instruction and arguments,if any and causes an implementation-defined action.

3)#define directive specifies a macro identifier and a replacement list,and terminates with a new line character.

#undef directive cancels a previous definition of the identifier by #define.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
q : explain the code for a beginner in c what each line do Question 2....
q : explain the code for a beginner in c what each line do Question 2. The following code defines an array size that sums elements of the defined array through the loop. Analyze the following code, and demonstrate the type of error if found? What we can do to make this code function correctly ? #include <stdio.h> #define A 10 int main(int argc, char** argv) { int Total = 0; int numbers[A]; for (int i=0; i < A; i++)...
When converting a source code file into an executable file, it must go through the preprocessor,...
When converting a source code file into an executable file, it must go through the preprocessor, then the compiler, and finally the linker. Each step may generate its own kind of error messages. Imagine that a programmer typed "isteam" instead of "iostream" in the #include directive when typing in the C++ source code file shown in Question #3. When the programmer later saved the file and then entered "g++ myCopy.cpp" on the command line, the following error messages appeared on...
#include <stdio.h> #pragma warning(disable : 4996) // CSE 240 Fall 2016 Homework 2 Question 3 (25...
#include <stdio.h> #pragma warning(disable : 4996) // CSE 240 Fall 2016 Homework 2 Question 3 (25 points) // Note: You may notice some warnings for variables when you compile in GCC, that is okay. #define macro_1(x) ((x > 0) ? x : 0) #define macro_2(a, b) (3*a - 3*b*b + 4*a * b - a*b * 10) int function_1(int a, int b) { return (3*a - 3*b*b + 4*a * b - a*b * 10); } // Part 1: //...
This question is in C++. For each code snippet below, write what the code outputs to...
This question is in C++. For each code snippet below, write what the code outputs to the standard output: (a) queue < int > q ; q . push (4); q . push (7); q . push (2); q . push (11); q . push (16); for ( int i = 0; i < q . size (); i ++) { q . push ( q . front () * 2); q . pop (); } while (! q ....
Let C be a 6-error correcting code. Using the definition of error correcting, explain how you...
Let C be a 6-error correcting code. Using the definition of error correcting, explain how you know that C is t-error correcting for all t ∈ {1, 2, 3, 4, 5}.
C++ //StudentDataStructure.txt //Student records are stored in a parallel-array Data Structure. Here is the code to...
C++ //StudentDataStructure.txt //Student records are stored in a parallel-array Data Structure. Here is the code to generate and populate Parallel-Array Data Structure: const int NG = 4; //Number of Grades string names[] = {"Amy Adams", "Bob Barr", "Carla Carr", "Dan Dobbs", "Elena Evans" }; int exams[][NG]= { {98,87,93,88}, {78,86,82,91}, {66,71,85,94}, {72,63,77,69}, {91,83,76,60} };    --------------------------------------------------------------------------------- 1 A) Create and Populate a Parallel-Array Data Structure using the code described in "StudentDataStructure.txt". B) Define a Record Data Structure for student records. It...
CAN YOU PLEASE WRITE THIS CODE IN A DIFFERENT WAY 'EASIER AND BETTER' QUESTION Using C++...
CAN YOU PLEASE WRITE THIS CODE IN A DIFFERENT WAY 'EASIER AND BETTER' QUESTION Using C++ 11. Write a function that will merge the contents of two sorted (ascending order) arrays of type double values, storing the result in an array out- put parameter (still in ascending order). The function shouldn’t assume that both its input parameter arrays are the same length but can assume First array 04 Second array Result array that one array doesn’t contain two copies of...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
C++ question. Please explain the code and how it resulted in the output. Explain each line...
C++ question. Please explain the code and how it resulted in the output. Explain each line along with the aspects of "buffers" if possible. Everything is listed below. Code below: #include <iostream> #include <string> using namespace std; int main() {    cout << boolalpha;    cout << static_cast<bool>(1) << endl;    cout << static_cast<bool>(0) << endl;    string s = "AAARGH!!!";    if (s.find("AAA")) { cout << 1 << endl; }    if (s.find("RGH")) { cout << 2 << endl;...
In assembler code must be a gcd.s file So here is the C code I have...
In assembler code must be a gcd.s file So here is the C code I have written originally for the program. My question is how do I convert it to assembly code? //C code #include <stdio.h> int fibonacci(int n) { if(n <= 2) { return 1; } else { return fibonacci(n-1) + fibonacci(n-2); } } int main(void) { int n; printf("Enter Fibonacci term: "); scanf("%d", &n); printf("The %dth Fibonacci number is %d\n", n, fibonacci(n)); return 0; } Instructions In C...