-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99a4827
commit e79a7ce
Showing
2 changed files
with
38 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |