C | Structure & Union | Question 9

filter_none

edit
close

play_arrow

link
brightness_4
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;
}

chevron_right


(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

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up