Biggest of 3 Numbers using Macros: C Program

In this video lets see how we can make use of Macros and ternary / conditional operator to find biggest of three numbers.

Related Read:
Biggest of 3 Numbers Using Ternary Operator: C
Preprocessors In C Programming Language

What we learn in this video tutorial?

We learn how to make use of nested ternary / conditional operator in macro definition. And how to use macro continuation( \ ) preprocessor operator.

Video Tutorial: Biggest of 3 Numbers using Macros: C Program



YouTube Link: https://www.youtube.com/watch?v=CYWSkQ2-kp4 [Watch the Video In Full Screen.]

Source Code: Biggest of 3 Numbers using Macros: C Program

#include<stdio.h>

#define BIGGEST(x, y, z) ( (x > y && x > z) ? x : ( y > z) ? y : z )

int main()
{
    int a, b, c;

    printf("Enter 3 integer numbers\n");
    scanf("%d%d%d", &a, &b, &c);

    printf("Biggest of 3 numbers is %d\n", BIGGEST(a, b, c));

    return 0;
}

Output:
Enter 3 integer numbers
20
50
60
Biggest of 3 numbers is 60

Here we’re writing logic inside macro expansion. Wherever macro template is found in our source code, preprocessor replaces that macro template with macro expansion and the compiler compiles the code like normal source code.

Nested Ternary / Conditional Operator

Here we are using nested conditional operator. First we check if value of a is greater b and c, if true, value of a will be returned orelse we check if b is greater than c, if true, value of b will be returned orelse value of c will be returned.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert