2 Years
Discussion Span
Last Post by Schol-R-LEA

Could be a abbreviation for microphone or microgram. Could you please be more specificic with your question?


//what would be output of this program.

#define abc(a) printf("%s=%s",#a,a)
void main()
char str[]="uday";

what is micro in c programming.

I believe the term you are going for is macro, not micro. A macro is a piece of code that gets replaced by another piece of code at compile time, before the compilation process proper begins. This is called macro expansion, and in C is mostly used as a way of getting the effect of a function without as much overhead. In C and C++, a macro is defined by a pre-processor statement, #define, which indicates that the macro name and parameter list immediately following the #define should be expanded to the . For example, the simple macro:

#define PI 3.1415

... in the following code

area = PI * r * r;

is textually expanded to

area = 3.1415 * r * r;

Note that this is an exact replacement of the string 'PI' with the string '3.1415' in the code itself; the compiler doesn't see the actual PI, just the 3.1415. This is important because there is no type checking or other protection in macros; if you had a macro:

#define SQUARE(x) x * x

and applied it to a sum,

area = PI * SQUARE(2 + 12);

you would get

area = 3.1415 * 2 + 12 * 2 + 12;

which almost certainly isn't what you intended.

For the macro you showed, things get a little more complicated, because it uses the dtringifying operator, #. What this does is cause the macro argument to be inserted as a C string into the macro expansion. The macro expansion for the invocation given would be:


Thus, for the code above, the result would be to print out, str == uday.

BTW, the main() function should always be delcared a returning an int value, and should return zero for a successful completion. The use of void main() was legal in older C code, but was never standard.

Edited by Schol-R-LEA

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.