What will be the Output of the Program?

By Anjnee Bhatnagar|Updated : June 29th, 2022

What will be the output of the program?

#include<stdio.h>

#include<string.h>

int main()

{

char str1[20]=”Hello”, str2[20]=”World”;

printf(“%s\n”, 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:

Comments

write a comment

Follow us for latest updates