C++ STRUCTURE AND UNION | C++ FOUNDATION Question 6

Last Updated :
Discuss
Comments

What will output of the following C++ code?

# include <iostream>
# include <string.h>
using namespace std;

struct Test
{
  char str[20];
};

int main()
{
  struct Test st1, st2;
  strcpy(st1.str, "GeeksQuiz");
  st2 = st1;
  st1.str[0] = 'S';
  cout << st2.str;
  return 0;
}

Segmentation Fault

geeksquiz


 

GeeksQuiz

Compiler Error


 

Share your thoughts in the comments