C | Structure & Union | Question 9
# 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
filter_none
(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
Recommended Posts:
- C | Structure & Union | Question 5
- C | Structure & Union | Question 7
- C | Structure & Union | Question 10
- C | Structure & Union | Question 10
- C | Structure & Union | Question 1
- C | Structure & Union | Question 6
- C | Structure & Union | Question 2
- C | Structure & Union | Question 8
- C | Structure & Union | Question 4
- Difference between Structure and Union in C
- Anonymous Union and Structure in C
- Output of C++ programs | Set 41 (Structure and Union)
- Output of C programs | Set 44 (Structure & Union)
- Union in C
- C | Loops & Control Structure | Question 17



