From 4bd4653028d9e52f6965400671cb109b60c9ec03 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Sun, 16 Oct 2022 08:21:03 +0530 Subject: [PATCH] struct_code.cpp The code Which explains about struct concept in CPP. One of the most asked code snippet in coding exams Contributed by Vaibhav Wani! --- struct_code.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 struct_code.cpp diff --git a/struct_code.cpp b/struct_code.cpp new file mode 100644 index 00000000..e90cc301 --- /dev/null +++ b/struct_code.cpp @@ -0,0 +1,19 @@ +#include +int main(){ + + struct xyz{ + + int x; + }; + + struct xyz obj1={1}; //creating struct object + struct xyz obj2= obj1; //Copy of that object + + printf("%d",obj2.x); //access using copy + obj2.x=100; //changing value using copy object + printf("%d",obj1.x); //access value using original object +return 0; +} +//Expected output: +1 +100