Question: In C language. PLEASE be detailed. Why does the first case uses the arrow operator to access digits while the second case uses the .
In C language. PLEASE be detailed. Why does the first case uses the arrow operator to access digits while the second case uses the . operator to access quizzes. Both are allocated structs with malloc for one of its members. Whats so different that different operators are used? Thank you.
//CASE 1) MAIN
struct integer { int* digits; int size; };
//FUNCTION:
struct nteger* createRandBigInt(intnumDigits) { struct nteger* temp;
temp = (struct *integer) malloc(sizeof(struct integer));
temp->digits = (int *) malloc(numDigits*sizeof(int)); //THIS LINE
temp->size = numDigits; temp->digits[numDigits-1] = 1+ rand()%9; int i; for(i=0; i
return temp; }
//CASE 2) In MAIN:
struct Student {
int student_id;
float *quizzes;
}
//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))); //THIS LINE
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
