So im just learning C but from my understand we can create Function Prototypes anywhere right?
So then when i was experimenting with function and structure why is it that. If i put the function prototype before the structure declaration is does not work but when i put the function prototype after the structure declaration it does work ?.
Could some kind soul explain this?
Before structure declaration (Does not Work)
/* Function Prototypes */
void printID(struct studentID person);
/* Structure Decleration */
struct studentID{
char Name[50];
int Age;
int Birth_Year;
};
int main(){
struct studentID me = {"BOB", 25, 1996};
printID(me);
return 0;
}
/* Function Details */
void printID(struct studentID person){
printf("Your Name is %s\n", person.Name);
printf("Your Age is %d\n", person.Age);
printf("Your date of birth is %d\n", person.Birth_Year);
}
After Structure declaration (Does Work)
/* Structure Decleration */
struct studentID{
char Name[50];
int Age;
int Birth_Year;
};
/* Function Prototypes */
void printID(struct studentID person);
int main(){
struct studentID me = {"BOB", 25, 1996};
printID(me);
return 0;
}
/* Function Details */
void printID(struct studentID person){
printf("Your Name is %s\n", person.Name);
printf("Your Age is %d\n", person.Age);
printf("Your date of birth is %d\n", person.Birth_Year);
}