Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what does %if mean in c programming

0 votes
asked Oct 14, 2022 by Robin Mwirigi (120 points)

1 Answer

0 votes
answered Oct 20, 2022 by Peter Minarik (86,180 points)
%if

Not much. Most probably a compilation error.

Can you share a code what you're exactly after?

If you're after the if, then it is the branching instruction that allows you to do an action only if a certain condition is met. See more details here.

e.g.:

if (number < 0)
    printf("negative number");
else
    printf("non-negative number");

If you're after the #if, it is a preprocessor directive that enables or disables code segments (some part of the code may or may not be compiled) based on a condition. More details here.

#include <stdio.h>

#ifdef __linux__
#define OS "Linux"
#else
#define OS "Windows"
#endif /* linux */
    
int main()
{
    printf(OS); // This prints "Linux" on OnlineGDB
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...