1/4
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
What is passing a structure to a function in c?
Definition:
Passing a structure to a function means sending structure data as an argument to a function.
Program:
#include <stdio.h>
struct student {
int id;
};
void display(struct student s) {
printf("%d", s.id);
}
int main() {
struct student s1 = {10};
display(s1);
return 0;
}
What is passing individual elements of a structure to a function?
Definition:
Passing individual elements means sending each member of the structures separately to a function.
Program:
#include <stdio.h>
struct student {
int id;
};
void display(int x) {
printf("%d", x);
}
int main() {
struct student s1 = {20};
display(s1.id);
return 0;
}
What is passing hole structure to a function?
Definition:
Passing hole structure means sending the complete structure variable as a single argument to a function.
Program:
#include <stdio.h>
struct book {
int price;
};
void show(struct book b) {
printf("%d", b.price);
}
int main() {
struct book b1 = {150};
show(b1);
return 0;
}
What is the difference between passing individual elements and whole structure.
Definition:
Individual elements are passed separately while the whole structure is passed as one argument.
Program:
// Individual element passing
display(s1.id);
// Whole structure passing
display(s1);