Discussion
Which of the following are correctly formed #define statements in C?
Answer: C
Correct answer: #define CUBE(X)(X*X*X)
The others each have a fault:
#define CUBE (X) (X*X*X);- the space after the name makes it an object-like macro whose body is the whole rest of the line, and the trailing semicolon travels with every use.#define CUBE(x) (X*X*X)- the parameter isxbut the body usesX, so the argument is never substituted.#define CUBE(X) {X*X*X}- braces make it a block, which cannot appear where a value is wanted.
Only the third is well formed - though ((X)*(X)*(X)) would be safer still.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development