Question: struct student { char name[20]; int idNo; double GPA; }; // creating struct named student included name,id and gpa int main() { struct student arr[3]

struct student

{

char name[20];

int idNo;

double GPA;

}; // creating struct named student included name,id and gpa

int main()

{

struct student arr[3] = {{"Bill Gates",1001,3.92},{"Steve Jobs",1002,3.44},{"Dennis Ritchie",1003,3.86}};

// create student name list

void printByIndex(struct student arr[],int size); // function prototype

` void printByReference(struct student* arr,int size); //function prototype

printByIndex(arr,3); // create printByindex function

printByReference(arr,3); // create printByRefenrece function

return 0;

}

void printByIndex(struct student arr[],int size) // print out list of student using array

{

int i=0; // loop counter

for(i=0;i

{

printf("%s %d %.2lf ",arr[i].name,arr[i].idNo,arr[i].GPA);//printing using dot operator on struct

}

printf(" ");

}

void printByReference(struct student* arr,int size) // print out list of student using pointer

{

int i = 0; // loop counter

const student*ref = arr; // declare student , ref and arr for pointer

for(i=0;i

{

printf("%s %d %.2lf ",ref->name,ref->idNo,ref->GPA); // print student list by reference

ref++;

}

printf(" ");

}

Please helping me fixing the program. void printByIndex and void printByreference, have to be inside the int main() function. void printByIndex(using array indexing) and printByreference(using pointer referencing). Thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!