fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct student* Student; // taking Student as pointer to Struct
  4. int initMemory(Student );
  5. struct student {
  6. char* mark; /* or array[2] like array[0] = 'A' , array[1] = 'B' */
  7. int age;
  8. int weight;
  9. };
  10.  
  11. typedef enum{
  12. MEMORY_GOOD,
  13. MEMORY_BAD} Status;
  14.  
  15. int main(int argc, char* argv[]) {
  16.  
  17. Status status;
  18.  
  19. Student john; /* Pointer to struct */
  20.  
  21. /* Function call to allocate memory*/
  22. status = initMemory(john);
  23. printf("got status code %d",status);
  24. }
  25.  
  26.  
  27. int initMemory(Student _st){
  28. _st = (Student)malloc(sizeof(Student));
  29.  
  30. printf("Storage size for student : %d \n", sizeof(_st));
  31. if(_st == NULL)
  32. {
  33. return MEMORY_BAD;
  34. } else {
  35.  
  36. char* _tmp = malloc(2*sizeof(char)); /* error: request for member 'mark' in something not a structure or union */
  37. _st->mark = _tmp;
  38. return MEMORY_GOOD;
  39. }
  40. }
  41.  
Success #stdin #stdout 0s 2300KB
stdin
Standard input is empty
stdout
Storage size for student : 4 
got status code 0