hamburger

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;

}

  1. Hello
  2. World
  3. Hello World
  4. World Hello

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:

Our Apps Playstore
POPULAR EXAMS
SSC and Bank
Other Exams
GradeStack Learning Pvt. Ltd.Windsor IT Park, Tower - A, 2nd Floor, Sector 125, Noida, Uttar Pradesh 201303 help@byjusexamprep.com
Home Practice Test Series Premium