Skip to content

Commit

Permalink
[NEW]
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonchen1998 committed Apr 5, 2024
1 parent f1bf5b5 commit d1e78b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Data-Structure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
29 changes: 29 additions & 0 deletions Data-Structure/code/Structure/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Example of a C++ program that uses a structure
#include <iostream>
#include <string>
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;
}

0 comments on commit d1e78b0

Please sign in to comment.