C examples for Operator:Conditional Operator
Guess a random number with the ? operator
#include <stdio.h> #include <stdlib.h> int main(void) { int magic;/* w w w. j a v a 2 s . c o m*/ int guess; magic = rand(); /* generate the magic number */ printf("Guess the magic number: "); scanf("%d", &guess); if (guess == magic) { printf("** Right ** "); printf("%d is the magic number", magic); } else guess > magic ? printf("High") : printf("Low"); return 0; }