Answer Posted / vadivel t
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 |
Post New Answer View All Answers
What is the difference between a function and a method in c?
How can you find the day of the week given the date?
What is a stream water?
Give basis knowledge of web designing ...
Differentiate abs() function from fabs() function.
Do you know the purpose of 'register' keyword?
What are valid signatures for the Main function?
What is null pointer in c?
What are the two types of structure?
What is wrong with this initialization?
What are comments and how do you insert it in a C program?
please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................
Can math operations be performed on a void pointer?
If i have an array 0 to 99 i.e,(Size 100) I place the values 1 to 100 randomly like a[0]=29,a[1]=56 upto array[99].. the values are only between 1 to 100. getting the array values by using scanf.. If i entered one wrong element value line a[56]=108. how can i find it.. and also how to find the missing value in 1 to 100.. and i want to replace the missing values.. any one of them know please post your answer..
What is page thrashing?