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
1.What is the output of the following code?char str[] = "hello";printf("%c\n", str[1]);
What is the output of the following code?char str1[] = "C programming";char str2[20];strcpy(str2, str1);printf("%s\n", str2);
What is the output of the following C code?char *ptr;char mystring[] = "abcdefg";ptr = myString;ptr += 5;
What will be the output of the following code?#include <stdio.h>int main() { int arr[4] = {0, 1, 2, 3}; printf("%d\n", arr[-1]); return 0;}
what is the output of the given program?main(){#ifndef sanprintf("no");#endifprintf("yes");}
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.