Skip to content

Commit

Permalink
update structures
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnologicalJerry committed Dec 26, 2022
1 parent 99a4827 commit e79a7ce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
28 changes: 11 additions & 17 deletions Structure.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@

#include<stdio.h>

struct Point
{
int x, y;
#include <stdio.h>
struct Point {
int x, y;
};

int main()
{
struct Point p1 = {1, 2};

// p2 is a pointer to structure p1
struct Point *p2 = &p1;

// Accessing structure members using structure pointer
printf("%d %d", p2->x, p2->y);
return 0;

int main() {
struct Point p1 = {1, 2};

struct Point *p2 = &p1;

printf("%d %d", p2->x, p2->y);
return 0;
}
27 changes: 27 additions & 0 deletions structures.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>

struct myStructure {
int myNum;
char myLetter;
};

int main() {

struct myStructure s1;
struct myStructure s2;

s1.myNum = 13;
s1.myLetter = 'B';

s2.myNum = 20;
s2.myLetter = 'C';

// Print values
printf("s1 number: %d\n", s1.myNum);
printf("s1 letter: %c\n", s1.myLetter);

printf("s2 number: %d\n", s2.myNum);
printf("s2 letter: %c\n", s2.myLetter);

return 0;
}

0 comments on commit e79a7ce

Please sign in to comment.