i am not getting this unexpected output..can u explain it??

#include<stdio.h>
#define FUN(arg) do{\ if(arg)\ printf(“CODECHEF…”, “\n”);\ }while(–i)
int main()
{
int i=2;
FUN(i<3);
return 0;
}

output-CODECHEF...CODECHEF...

hey hw to format this code … i dnt know …:stuck_out_tongue:

printf(“CODECHEF…”, “\n”);
will print “CODECHEF…”; Since, there is no “%s” in the first parameter of the printf() for the “\n” to apply.

The rest is rest self explanatory if you expand the macro.

2 Likes

but m not getting , y shlashes \ are there?? y they are used???

I believe this question is from indiabix.com and indiabix.com has forum discussion for each question just click “Discuss in forum” button below question.

perhaps m getting… they are for new line… i guess???

sure i will

It is same as :

do{
    if(2 < 3)
    printf("CODECHEF...", "\n");
}while(--2)

About Slashes :

  • Preprocessor directives and macro references have syntax that is independent of the C language. Follow these rules when specifying macro definitions:
  • The macro name and the formal parameters are identifiers and are specified according to the rules for identifiers in the C language.
  • Spaces, tabs, and comments may be used freely within a #define directive anywhere that the delta symbol () appears in the following example:

Eg Syntax: #define name( parm1 , parm2 ) \

  • Spaces, tabs, and comments are replaced by a single space.

  • White space cannot appear between the name and the left parenthesis that introduces the parameter list. White space may appear inside the replacement list. Also, at least one space, tab, or comment must separate name from define .

4 Likes
//