See sometimes I have
typedef struct _student
{
// some data
} STUDENT;
NOW
main()
{
int noOfStudent;
STUDENT *b;
//some work
noOfstudent = this_much_student();
STUDENT a[noOfStudent]; // way 1
b=(STUDENT*)malloc(sizeof(STUDENT)*noOfStudent); // way 2
}
Somewhere I read that all variables should be defined
at the beginning of a function and the defination of variables in the middle of function should be ignored, So in such condition
does way1 is good ? or way2 is good ? and why?(Justify)
Edit : i am coding to target c89 compiler and i want the scope is limited to this function only