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 |
Write a c program to print the sizes and ranges of different data types in c?
if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0
Tell us the use of fflush() function in c language?
What is the role of this pointer?
Write a code to achieve inter processor communication (mutual exclusion implementation pseudo code)?
What does 3 mean in texting?
write a method for an array in which it can display the largest n next largest value.
how to find out the inorder successor of a node in a tree??
How do you declare a variable that will hold string values?
who invented c
#include<stdio.h> int f(int,int); int main() { printf("%d",f(20,1)); return 0; } int f(int n,int k) { if(n==0) return 0; else if(n%2)return f(n/2,2*k)+k; else return f(n/2,2*k)-k; } how this program is working and generating output as 9....?
being a chemical engineer and with an aggregate of 80% why you opt for TCS and not your core industry?