USING MACROS IN C;

QUESTION- WAP to use the #define function in a c program as an operator;

ANSWER-

#include<stdio.h>
#include<conio.h>
#define D ||
#define G &&
int main()
{
int p=10,q=20,r=30;
if((p==10) G (q<25 D r>=50))
printf(“\nCONDITION TRUE!!”);
else
printf(“\nCONDITION FALSE!!”);
printf(“\n\nPROGRAMMING AT C#ODE STUDIO”);
getch();
return 0;
}

macro

#define fn. ; (use);

QUESTION- Use define for a vehicle’s variant, model, type and print choice as you define;

ANSWER-

#include<conio.h>
#include<stdio.h>
#define petrol 0
#define diesel 1
#define tw 2
#define fw 3
#define nw 4
#define old 5 //here we define all the data
struct vehical
{
    unsigned variant:1;
    unsigned type:2;
    unsigned model:3;
};
int main()
{
    struct vehical s;
    s.variant=petrol;
    s.type=fw;
    s.model=nw;
    printf(“\n HERE IS YOUR CHOICE : \n\n”);
    printf(“\nModel=%d\nVariant=%d\nType=%d”,s.model,s.variant,s.type);
    printf(“\n\n\tPROGRAMMING @ CODE STUDIO”);
    getch();
}

 

Output-

DEF