C Programming - C Preprocessor - Discussion

Discussion Forum : C Preprocessor - Point Out Correct Statements (Q.No. 2)
2.
Which of the following are correctly formed #define statements in C?
#define CUBE (X) (X*X*X);
#define CUBE(x) (X*X*X)
#define CUBE(X)(X*X*X)
#define CUBE(X) {X*X*X}
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
31 comments Page 2 of 4.

Neetu said:   1 decade ago
Option (A) is not right because there is a space btw CUBE and (X) , if we remove the space, it'll be correct.

And also it is not necessary to place semicolon at the end of macro, so option (C) is also correct.

Shankar meena said:   1 decade ago
My answer is for @Chaitali and @Vishnu.

[A]. #define CUBE (X) (X*X*X);
[B]. #define CUBE(x) (X*X*X)

For ans [A]. #define is a preprocessor directive. It is not a statement so we are not semicolon.

For ans [B]. #define is used for declare a symbolic constant. And in the constant we are used all letter is capital.

So, the answer A and B is incorrect and C is correct.

Aniruddh said:   1 decade ago
Not only 3 but all 4 macro definitions are working properly with dev cpp compiler.

Rajesh.T.K. said:   1 decade ago
In GCC compiler, semicolon and space doesn't matter. But what happens with Turbo C compiler? can anyone explain me?

Suhas said:   1 decade ago
Semi colon does not matter in macros.
It depends on compiler you are using like Turbo C (windows) and GCC in linux.

Nimesh said:   1 decade ago
The mai error in option A is because space between
CUBE and (X)...check out CUBE (X)

Ketan said:   1 decade ago
After the #define their is spac important for defining process and than no semicolon after that.

Chaitali said:   1 decade ago
Why not a or b?
Please explain...

Aarti said:   1 decade ago
a)option will not work as there is space between cube(x) (x*x*x).
if we write cube(x)(x*x*x),then it will compile.there is no effect of semicolon.
b)will not work because macro is defined cube(x)(X*X*X)
this will give error "undefined symbol X".
c)option will work

Annanya said:   1 decade ago
Space is must in preprocessor declaration then how came the answer c? can anybody explains?


Post your comments here:

Your comments will be displayed after verification.