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?
Discussion:
31 comments Page 2 of 4.
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.
It depends on compiler you are using like Turbo C (windows) and GCC in linux.
Sai kumar said:
1 decade ago
Here OPTION A is correct in some cases but other options are absolutely wrong.....given below is example for the answer.
According to statements written in main.
for example
1. #define CUBE(X) (X*X*X);
this will be correct when we have statement like
main
{
int a;
a=CUBE(a) //this will be replaced by (a*a*a); along with semicolon // which is syntactically correct
}
BUT C IS NOT CORRECT AS SPACE IS NOT GIVEN.
According to statements written in main.
for example
1. #define CUBE(X) (X*X*X);
this will be correct when we have statement like
main
{
int a;
a=CUBE(a) //this will be replaced by (a*a*a); along with semicolon // which is syntactically correct
}
BUT C IS NOT CORRECT AS SPACE IS NOT GIVEN.
Ketan said:
1 decade ago
After the #define their is spac important for defining process and than no semicolon after that.
Nimesh said:
1 decade ago
The mai error in option A is because space between
CUBE and (X)...check out CUBE (X)
CUBE and (X)...check out CUBE (X)
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
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
Hriday Kumar Gupta said:
1 decade ago
Before Explanation of all the options, need to know that, in Macro definition(#define CUBE(X) (X*X*X)), there are Macro Expansion and Macro Templates.
In given Question, #define CUBE(X) (X*X*X) is Macro definition, CUBE(X) is Macro-Templates and (X*X*X)is Macro-Expansion.
A. Macro-Expansion must not followed by semicolon(;)
B. In Macro-Expansion and Macro-Templates using different variables(i.e x and X)
C. Correct Answer according to Macro definition.
D. Wrong, because only parenthesis i.e () is allowed in Macro-Expansion.
Thank You.
In given Question, #define CUBE(X) (X*X*X) is Macro definition, CUBE(X) is Macro-Templates and (X*X*X)is Macro-Expansion.
A. Macro-Expansion must not followed by semicolon(;)
B. In Macro-Expansion and Macro-Templates using different variables(i.e x and X)
C. Correct Answer according to Macro definition.
D. Wrong, because only parenthesis i.e () is allowed in Macro-Expansion.
Thank You.
(1)
Annanya said:
1 decade ago
Space is must in preprocessor declaration then how came the answer c? can anybody explains?
Rajan said:
1 decade ago
'c' is correct one because of it has neither semicolon nor lower case.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers