c question mark
#include <stdio.h>
int main() {
int x = 5;
int y = 10;
int result;
result = (x > y) ? x : y;
printf("The larger value is: %d", result);
return 0;
}
Explanation:
- #include <stdio.h>
: Includes the standard input/output library for using functions like printf
.
- int main()
: The main function where the program execution begins.
- int x = 5;
: Declares and initializes an integer variable x
with the value 5.
- int y = 10;
: Declares and initializes an integer variable y
with the value 10.
- int result;
: Declares an integer variable result
without initialization.
- result = (x > y) ? x : y;
: Uses the ternary operator (? :
) to assign the larger of x
and y
to the variable result
. If the condition (x > y)
is true, it assigns the value of x
; otherwise, it assigns the value of y
.
- printf("The larger value is: %d", result);
: Prints the result using printf
with a format specifier %d
for integers.
- return 0;
: Indicates successful execution and termination of the program.