Once you attempt the question then PrepInsta explanation will be displayed.
char ch; declares a variable ch of type char.
ch = 'P'; assigns the value 'P' to the variable ch.
printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'p' - 'P' : ch); prints the result of the ternary expression.
The ternary expression checks if ch is within the uppercase letter range ('A' to 'Z'). If it is true, it adds the difference between the ASCII values of 'p' and 'P' to ch. Otherwise, it uses the original value of ch.
return 0; ends the program and returns 0 to the operating system.
Now, let's evaluate the program for the character 'P':
ch is assigned the value 'P'.
The ternary expression is evaluated: 'P' is indeed between 'A' and 'Z', so the expression 'P' + 'p' - 'P' is calculated:
ASCII value of 'p' = 112
ASCII value of 'P' = 80
Difference = 112 - 80 = 32
'P' + 32 gives 'p'.
Login/Signup to comment