Find output of the below program:int main(){ char str[]={'e','a','r','t','h'}; printf("%s", str); return 0;}
Question
Find output of the below program:int main(){ char str[]={'e','a','r','t','h'}; printf("%s", str); return 0;}
Solution
To find the output of the given program, let's analyze it step by step:
- The program starts with the main function.
- Inside the main function, a character array named "str" is declared and initialized with the characters 'e', 'a', 'r', 't', and 'h'.
- The printf function is called with the format specifier "%s" and the variable "str" as the argument. This format specifier is used to print a string.
- The program then returns 0, indicating successful execution.
Based on the code, the expected output of the program is the string "earth".
Similar Questions
What will be the output of the following code?#include <stdio.h>int main() { char str[] = "Programming"; printf("%s\n", str + 3); return 0;}
What is the output of the following code?char str[] = "world";printf("%s\n", str + 2);
What will be the output of the following code?#include <stdio.h>#include <string.h>int main() { char str1[] = "Hello"; char str2[10]; strcpy(str2, str1); printf("%s\n", str2); return 0;}
What will be the output of the following C program?#include<stdio.h>int main(){ char str[] = "Nagpur"; str[0]='K'; printf("%s, ", str); str = "Kanpur"; printf("%s", str+1); return 0;}Select one:Nagpur, KanpurErrorKagpur, KanpurKagpur, anpur
What is the output of the following code?char str[] = "hello";int len = strlen(str);printf("%d\n", len);
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.