logo

The conditional operator (or ternary operator) in C

#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char* argv[]) { int x, y; scanf("%d", &x); scanf("%d", &y); int max = x > y ? x : y; /*if (x > y) { max = x; } else { max = y; }*/ printf("Maximum is %d\n", max); return 0; }
Course thumb

The C programming language made simple