Skip to content

Commit

Permalink
[NEW] structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonchen1998 committed Apr 5, 2024
1 parent 3cc8f3b commit f1bf5b5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Data-Structure/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# Data-Structure

> Here we use C / C++ / Python to implement some data structures. Notes from W3Schools.
## Table of Contents

- [Structure](#Structure)
- [Pointer](#Pointer)

## [Structure](https://www.w3schools.com/cpp/cpp_structs.asp)

> [Example C program](./Structure/structure.c)
Structure is a user-defined data type in C which allows to combine data items of different kinds.

## Pointer

28 changes: 28 additions & 0 deletions Data-Structure/code/Structure/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Example of a C program that uses a structure
#include <stdio.h>
#include <string.h>

// Define a structure
struct Student {
char name[50];
int age;
float marks;
};

int main() {
// Declare a structure variable
struct Student student1;

// Assign values to student1
strcpy(student1.name, "John");
student1.age = 21;
student1.marks = 88.5;

// Print student1 information
printf("Student 1\n");
printf("Name: %s\n", student1.name);
printf("Age: %d\n", student1.age);
printf("Marks: %.2f\n", student1.marks);

return 0;
}

0 comments on commit f1bf5b5

Please sign in to comment.