Simple Ternary operator : Operator Ternary « Language Basics « C / ANSI-C






Simple Ternary operator

#include <stdio.h>

int main(void)
{
  int i;

  printf("Enter a number: ");
  scanf("%d", &i);

  i = i > 0 ? 1: -1;

  printf("i =  %d", i);

  return 0;
}


           
       








Related examples in the same category

1.Ternary (?) operator
2.Use ternary operator in printf
3.Operator which accepts three value
4.Add function to the Ternary operator
5.Ternary operator inside if else
6.Write expression inside Ternary operator