What will be the Output of the Program?
By BYJU'S Exam Prep
Updated on: September 25th, 2023
What will be the output of the program?
#include
#include
int main()
{
char str1[20]=”Hello”, str2[20]=”World”;
printf(“%sn”, strcpy(str2, strcat(str1, str2)));
return 0;
}
- Hello
- World
- Hello World
- World Hello
Table of content
Answer: Option C. Hello World
The output of the program will be: Hello World
Solution
In the program, two character arrays are declared, namely str1 and str2. The char array str1 is initialized with ”Hello”, and str2 is initialized with “World”. Now in the printf statement strcat function concatenates or appends str2 at the end of str1. So str1 contains the value “Hello World”. Next strcpy function copies this value to the str2 array, and finally printf statement prints Hello World as the output.
☛ Related Questions: