What will be the output of the following code?#include <stdio.h>int main() { char str[] = "ABCDE"; printf("%c\n", str[2] + 3); return 0;}
Question
What will be the output of the following code?#include <stdio.h>int main() { char str[] = "ABCDE"; printf("%c\n", str[2] + 3); return 0;}
🧐 Not the exact question you are looking for?Go ask a question
Solution
The output of the code will be 'F'.
Explanation:
- The code declares a character array
str[]with the string "ABCDE". - The
printffunction is used to print the character at index 2 of the arraystr[], which is 'C'. - The ASCII value of 'C' is 67. The code adds 3 to this ASCII value, resulting in 70.
- The ASCII value 70 corresponds to the character 'F'.
- Therefore, 'F' is printed as the output.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.