Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copies a BMP file
- #include <stdio.h>
- #include <stdbool.h>
- struct student {
- int age;
- bool enrolled;
- char *student_name;
- };
- void test_struct(struct student);
- void print_student(struct student);
- int main(int argc, char *argv[])
- {
- struct student mike;
- mike.student_name = "Mike";
- mike.age = 19;
- mike.enrolled = false;
- print_student(mike); // $ Mike, 19, not enrolled
- test_struct(mike); // $ We pass the struct by value and change it.
- print_student(mike); // $ Mike, 19, not enrolled -- the changes we made in `test_struct` are forgotten
- return 0;
- }
- void test_struct(struct student s)
- {
- s.student_name = "James";
- s.age = 25;
- s.enrolled = true;
- print_student(s); // $ James, 25, enrolled
- }
- void print_student(struct student s)
- {
- printf("%s, %i, %s\n", s.student_name, s.age, s.enrolled ? "enrolled" : "not enrolled");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement