C Language Tutorials by Ghulam Murtaza Dahar - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Example of conditional operator

#include <stdio.h>

int main(){

char feb;

int days;

printf("Enter l if the year is leap year otherwise enter 0: ");

scanf("%c",&feb);

days=(feb=='l')?29:28;

/*If test condition (feb=='l') is true, days will be equal to 29. */

/*If test condition (feb=='l') is false, days will be equal to 28. */

printf("Number of days in February = %d",days);

return 0;

}