Home > Software design >  What is the role of identifier in C preprocessor directives
What is the role of identifier in C preprocessor directives

Time:03-22

When I execute the following code, the output is 5 6.

int main()
{
    int one = 5, two = 6;
    #ifdef next
    one = 2;
    two = 1;
    #endif
        printf("%d %d", one, two);
    return 0;
}

Definitely the code within #ifdef #endif is not getting excuted. I am unable to understand the utility of the identifier next. What is the keyword instead of next that will make the compiler execute the code inseide the #ifdef #endif section?

reference

CodePudding user response:

You simply define the macro

#define next
int main()
{
    int one = 5, two = 6;
    #ifdef next
    one = 2;
    two = 1;
    #endif
        printf("%d %d", one, two);
    return 0;
}

Now the values will change.

  • Related