Sunday, July 12, 2009

What is difference between #include and #define? and also what about inline and macro in c, c++?

#include tells the compiler to compile the specified file along with the source.





#define is used for macros; for example, you could use





#define min( a, b ) ( ( a ) %26gt; ( b ) ? ( b ) : ( a ) )





just like you would a function; however, it won't check your types, and your arguments may have unintended effects. The difference from inline is that the compiler will replace the "calls" to the macro with the actual text before compilation.





It can also be used to define constants, such as





#define e 2.718282f





inline tells the compiler to insert the function body wherever it is called; this eliminates the overhead of the function call. It is better to use inline functions over function like macros whenever possible.

What is difference between #include and #define? and also what about inline and macro in c, c++?
#include includes a file


#define means creating the static value.





ex: #include %26lt;stdio.h%26gt;


here including the header file .





#define venkat printf





we can use this as printf


ex:


venkat("This is venkatesh");
Reply:hi





#include is used to include a header file into a c/c++ program





#define is used to define a constant eg- #define pi 3.14





inline are function defined inside a class





i forgot wat a macro is





gud luc


No comments:

Post a Comment