Question: How come for the first case an arrow operator is used to access digits but for the second case the . operator is used to
How come for the first case an arrow operator is used to access digits but for the second case the . operator is used to access quizzes.
1)
In main:
struct integer { int* digits; int size; };
in function:
structinteger* createRandBigInt(intnumDigits) { structinteger* temp;
temp = (struct *integer) malloc(sizeof(struct integer)); temp->digits = (int *) malloc(numDigits*sizeof(int)); temp->size = numDigits; temp->digits[numDigits-1] = 1+ rand()%9; int i; for(i=0; i
2) In Main:
struct Student {
int student_id;
float *quizzes;
}
in function:
struct Student* AllocateStudents( int N, int Q) { struct Students *ptr; int i, j; ptr = (struct Student*) malloc(N *(sizeof(struct Student))); for(i = 0; i < N; ++i) { scanf("%d", &ptr[i].student_id); ptr[i].quizzes = (float *)malloc(Q * (sizeof(float))); for(j = 0; j < *noofquiz; ++j) { scanf("%d", &ptr[i].quizzes[j]); } } return ptr; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
