devxlogo

Short Expressions

Short Expressions

C++ has an alternative for the if condition using the sign “?”. The syntax for this condition is : “condition”?”case true”:”case false”.

For example, a function to return the maximum of two numbers looks like this:

inline int max(int a, int b) {return a>b?a:b;}

Another short expression allowed by C++ is used when you’re attribuing a value higher (or lower) than the current value stored in a variable. This can be used, for instance, when determining the maximum(or minimum) of some numbers.

Example:

max>?=5; - this will change max to 5 only if max is lower than 5min
See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist