top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is a Macro in C/C++ and what is its disadvantage?

+1 vote
353 views
What is a Macro in C/C++ and what is its disadvantage?
posted Jan 21, 2015 by Alwaz

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes
 
Best answer

Macros are the identifiers that represent statements or expressions in other words macros are fragment of code which is been given a name.

define directive is used to define a macro.

Example, we have define a macro i.e SQUARE(x) x*x.

Here the macro determines the square of the given number. Macro Declaration: #define name text

Disadvantage of using Macro:

The major disadvantage associated with the macro is :
1. When a macro is invoked no type checking is performed.
Therefore it is important to declare a macro coreectly so that it gives a correct answer whenever it is called inside the program.

answer Jan 22, 2015 by Mohammed Hussain
Similar Questions
0 votes
#define MY_STRUCT
typedef struct{ 
...
... 
} my_struct;

Above code is giving me error (MY_STRUCT) is not working as expected, Looks that some silly mistake, please point out as I have wasted many hours?

Sorry for hiding my identity?

+1 vote

Let me put some context of my curiosity -
One of the mysterious activities in Programming Language design is the aspect of standard libraries and there have been talk of "modernizing" standard libraries to meet up to the requirements:
i) Parallelism(multi-core)
ii) Searching
iii) Big data
iv) GUI lacking in C & C++
v) The top N widely used algorithms

Now as a developer I am interested to know, Is there a precise formula for the evolution of Standard Libraries and measure its effectiveness?

...