This C++ program computes the maximum value using macros. A macro is a #define preprocessor directive which give instruction to the compiler to preprocess the information before actual compilation starts. All subsequent occurrences of macro in the program will be replaced by replacement-text before the program is compiled. The macro-text should be written carefully using parentheses as several complications may occur while compiling.
Here is the source code of the C++ program computes the maximum value using macros. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
* C++ Program to Find Maximum Value using Macros
#define MAX(a, b) (a > b ? a : b)
int a = 10, b = 20, c = -30;
std::cout << "MAX(10, 20) = " << MAX(a, b)
std::cout << "MAX(-30, 20) = " << MAX(c, b)
Maximum of 10 and 20 = 20
Maximum of -30 and 20 = 20
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
If you wish to look at all C++ Programming examples, go to C++ Programs
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1,
- Chapterwise Mock Tests: Chapter 1,
, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry
. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms.
Stay connected with him at LinkedIn
Subscribe to his free Masterclasses at Youtube
& technical discussions at Telegram SanfoundryClasses