Hi I'm a beginner and I'm trying to work out some pointer to function examples. I can't even compile my code, it shows the following message. I cannot determine why I am getting the compilation errors.
/tmp/cc0qghbo.o: In function `main':
pointer_to_function_inside_structure.c:(.text+0x88): undefined reference to `func_ptr'
collect2: ld returned 1 exit status
here is my code, please tell me what I'm doing wrong
#include<stdio.h>
#include<stdlib.h>
struct student_data
{
char *name;
int roll_num;
int marks;
void (* func_ptr)(struct student_data *ptr);
};
void print_data(struct student_data *ptr);
void print_data(struct student_data *ptr)
{
printf("\nNAME OF THE STUDENT %s", ptr -> name);
printf("\nROLL NUMBER OF STUDENT %d", ptr -> roll_num);
printf("\nMARKS OF STUDENT %d\n", ptr -> marks);
}
int main()
{
struct student_data *ptr;
ptr -> name = "ajish";
ptr -> roll_num = 2;
ptr -> marks = 50;
ptr -> func_ptr = &print_data;
func_ptr(ptr);
}