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
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.
What is a pointer and how it is initialized?
What is the purpose of 'register' keyword in c language?
a program that performs some preliminary processing in C, it acts upon certain directives that will affect how the compiler does its work a) compiler b) loader c) directive d) preprocessor
write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.
What are preprocessor directives?
Why are algorithms important in c program?
What is the acronym for ansi?
What is a pragma?
For what purpose null pointer used?
write an interactive C program that will encode or decode a line of text.To encode a line of text,proceed as follows. 1.convert each character,including blank spaces,to its ASCII equivalent. 2.Generate a positive random integer.add this integer to the ASCII equivalent of each character.The same random integer will be used for the entire line of text. 3.Suppose that N1 represents the lowest permissible value in the ASCII code,and N2 represents the highest permissible value.If the number obtained in step 2 above(i.e.,the original ASCII equivalent plus the random integer)exceeds N2,then subtract the largest possible multiple of N2 from this number,and add the remainder to N1.Hence the encoded number will always fall between N1 and N2,and will therefore always represent some ASCII character. 4.Dislay the characters that correspond to the encoded ASCII values. The procedure is reversed when decoding a line of text.Be certain,however,that the same random number is used in decodingas was used in encoding.
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
Explain what is the difference between #include and #include 'file' ?
What is the process to generate random numbers in c programming language?
Is c easier than java?