All articles
c

A program to explain macros with ARGUMENTS

Share this article

Share on LinkedIn Share on X (formerly Twitter)

C Programming Language 097

  • Write a program to explain macros with ARGUMENTS

Program

#include <stdio.h>
#define add(x, y) (x + y)
 
void main()
{
    int a, b;
    float res;
 
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);
 
    res = add(a, b);
    printf("Sum = %f", res);
 
    printf("\n");
}

Result

Enter two numbers: 2 4
Sum = 6.000000

Comments