answersLogoWhite

0

All pre-processor directives begin with a # symbol. One of the most-used pre-processor directives is the #define directive, which has the following syntax:

#define SYMBOL definition

This defines a macro. During preprocessing, all occurrences of SYMBOL within your source code will be replaced with whatever is written in the definition (which includes everything up to the end of the line).

#define PI 3.14159

Here, all occurrences of the symbol PI within your source code will be replaced with the character sequence 3.14159. So if your source contained the following function:

double area_of_circle (double radius) {

return 2*PI*radius*radius; // 2 PI r squared

}

The compiler will see the following instead:

double area_of_circle (double radius) { return 2*3.14159*radius*radius;

}

While this may well seem a convenient method of defining constants, it is not. Macros should never be used to define constants. If you need a constant, use an actual constant. If the constant must be calculated at compile time, then use a constant expression. In this case we can define PI as follows:

constexpr double PI (void) {

return 4.0 * atan (1.0);

}

Note that the literal value 3.14159 takes no account of the implementation's precision because the compiler will convert it to a value of 3.141590. By defining the constant expression, the compiler will use a value of 3.14159265359..., including as many digits of precision as the implementation will physically allow, and thus minimising rounding errors.

Macros (#defines) should only be used for conditional compilation, never to define constants.

User Avatar

Wiki User

9y ago

What else can I help you with?

Continue Learning about Engineering

What are effect of logical errors?

The program doesn't work properly, e.g. generates invalid output.


What is top down stepwise refinement in c?

It is a designing method, but has nothing to do with the C language. No its a very useful technique of C programming In top down stepwise refinement we start with a psuedocode (it is actually a puseudocode) First the "Top"...is a single statement, in effect the complete representation of programme. but cannot give all the details so we do some refinement We do refinements in steps, like specifing variables and then again refine them by intializing them with specific or desired numbers or values. So top down stepwise refinements make it easy for us to design a programme...we divide our program from top to down in segments and refine (or define) these segments.


What is the effect of dereferencing a null pointer variable?

You'd get a memory access violation. Nothing serious besides the fact that your program crashes (which is a good thing).


Define Maximum power point tracking of solar cell under partial shading conditions?

in shading conditions also the solar raditions will reach the earth i think this will not effect the solar panels and also the mppt in shading conditions also the solar raditions will reach the earth i think this will not effect the solar panels and also the mppt


How do you define attributes for all the elements with one specific class using CSS?

Try this technique: ---- .class {attribute:value; attribute:value;} ---- This will effect any element with the class name .class. That means img.class, a.class, and div.class, for example, would be effected.

Related Questions

What is an if an then statement?

statement is a cause and effect statement. If addresses the cause and then address then effect. For example if I crave chocolate then I will have a mint instead. They are often used to cause change in habits.


Identity five types of taxes you are familiar with Define each type and explain its assume effect?

identity five types of taxes you are familiar with. Define aech type and explain its assume effect?identity five types of taxes you are familiar with. Define aech type and explain its assume effect?


What are the best ways to describe or define a cause and an effect?

A cause makes an effect happen, and an effect comes about as a result of a cause.


What is account statement?

An account statement is a record of transactions and their effect on bank account balances.


What is an account statement?

An account statement is a record of transactions and their effect on bank account balances.


Define ecological thread?

what is ecological effect on BT telcom?


What are the effect when a bank reconciliation statement is not prepared?

what is impact for brs statement does not tally may i know about the answer


The most important thing to consider in an opening statement is the effect that each and every statement will have on the?

Jury


Does ratify and effect mean the same thing?

no they do not because ratify means define an effect means what happens after the inncedent.


The most important thing to consider in an opening statement is the effect that each and every statement will have one the?

Jury


Identify the statement that correctly defines cause and effect?

An effect comes about as a result of a cause and a cause makes an effect happen.


What is a trigger in dbms?

Trigger is a statement that is automatically executed by the system as a side effect of a modification to the database. Several existing systems have their own non standard trigger functions. For a trigger we need to specify the condition under which the trigger is executed.