Skip to content
Related Articles

Related Articles

C | Structure & Union | Question 9
  • Difficulty Level : Medium
  • Last Updated : 27 Aug, 2013
GeeksforGeeks - Summer Carnival Banner




# 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;
}

(A) Segmentation Fault
(B) SeeksQuiz
(C) GeeksQuiz
(D) Compiler Error


Answer: (C)

Explanation: Array members are deeply copied when a struct variable is assigned to another one. See Are array members deeply copied? for more details.

Quiz of this Question

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :