what is the disadvantage of using macros?
Though, macro has advantages... it hav few disadvantages
too...
------------------------------------------------------------
1.1st disadvantage is, In debugging time u can't see the
value of the macro assigned to it.
So, u have to have ur source file, to fine out the value of
the macro.
But nowadays there are some debuggers which are capable of
showing the value of macro in debugging time.
------------------------------------------------------------
2.Dont use macro for typedef or be cautious before use.
Ex:
lets say, u wanted to have a macro, which can be used to
represent a declaration to an int pointer
#define INTPTR int*
in main..
main()
{
INTPTR a, p;
/*here, our understanding will be 'a' and 'p' both are int
pointers*/
}
but in preprocessor time macro shall be replaced like this -
> int* a, p;
so only 'a' will be treated as int pointer and 'p' shall a
normal int variable.
So tyr to avoid using MACRO for typedef.
use -> typedef int* INTPTR, So that u can achieve desired
result.
------------------------------------------------------------
3.Be carefull while using macro in arithmatic operation.
Ex:
#define MUL(a,b) a*b
In main...
main()
{
int a = 3, b = 4;
....
....
.....
printf("%d", MUL(a+1, b+1));
/*Here u may expect the result 4 * 5 = 20 but the result
would be 8*/
}
lets analise,
in preprocessing time macro shall be replaced as below;
MUL(a+1, b+1) - > 3+1*4+1, so result would be 8.
To avoid the unexpected result.
Define macro lik ...
#define MUL(a,b) (a)*(b)
------------------------------------------------------------
| Is This Answer Correct ? | 5 Yes | 3 No |
Who developed c language and when?
Write a program to write a given string in maximum possibilities? i.e str[5]="reddy"; i.e we can write this string in 120 ways for that write a program
how to swap 2 numbers within a single statement?
Program to find the absolute value of given integer using Conditional Operators
cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration
find largest of 3 no
Can you pass an entire structure to functions?
what are the general concepts of c and c++
provide an example of the Group by clause, when would you use this clause
how can we Declare a variable in c without defining it.
What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?
Write a program to generate prime factors of a given integer?