diff --git a/Data-Structure/README.md b/Data-Structure/README.md index 9e7966c..b960969 100644 --- a/Data-Structure/README.md +++ b/Data-Structure/README.md @@ -9,9 +9,12 @@ ## [Structure](https://www.w3schools.com/cpp/cpp_structs.asp) -> [Example C program](./Structure/structure.c) +> Example: [C](./code/Structure/example.c) | [C++](./code/Structure/example.cpp) -Structure is a user-defined data type in C which allows to combine data items of different kinds. +Structure is a user-defined data type in C or C++ that allows to combine data items of different kinds. ## Pointer +> Example: [C](./code/Pointer/example.c) | [C++](./code/Pointer/example.cpp) | [Python](./code/Pointer/example.py) + +A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. diff --git a/Data-Structure/code/Structure/example.cpp b/Data-Structure/code/Structure/example.cpp new file mode 100644 index 0000000..e35d614 --- /dev/null +++ b/Data-Structure/code/Structure/example.cpp @@ -0,0 +1,29 @@ +// Example of a C++ program that uses a structure +#include +#include +using namespace std; + +// Define a structure +struct Person { + string name; + int age; + float salary; +}; + +int main() { + // Declare a structure variable + Person p1; + + // Assign values to members of the structure variable + p1.name = "John"; + p1.age = 25; + p1.salary = 25000.50; + + // Display the values of the structure variable + cout << "Person Details" << endl; + cout << "Name: " << p1.name << endl; + cout << "Age: " << p1.age << endl; + cout << "Salary: " << p1.salary << endl; + + return 0; +} \ No newline at end of file