title: Compiler error (lvalue required as left operand of assignment) when using malloc
body: <p>I got 2 structs,a pointer to each struct and a void <code>**stack</code> which points to the pointers of the structs.</p>
  
  <p>my problem is at the line </p>
  
  <pre><code>(*ptr2+*a)=(struct student *)malloc(sizeof(struct student));
  </code></pre>
  
  <p><code>*a</code> is a variable that increases by 1 everytime a stud registration happens so i don't allocate memory for the same address over and over again</p>
  
  <p>since i send the address of <code>stud(&amp;stud)</code> at the menu function and then at the input function</p>
  
  <pre><code>*ptr2==stud 
  </code></pre>
  
  <p>thus </p>
  
  <pre><code>stud[*a]== *(stud+*a)== *(*ptr2+*a)
  </code></pre>
  
  <p>why is <code>(*ptr2+*a)</code> on the left side of <code>malloc</code> wrong?
  part of the code</p>
  
  <pre><code>struct student
  {
      char flag;
      char surname[256];
      int semester;
  };
  
  main()
  {
      ...
      struct student *stud;
      menu(stack,stackcopy,reversedstack,&amp;prof,&amp;stud,stacksize,&amp;head);
      ...
  }
  
  void menu(void **stack,void **stackcopy,void **reversed,struct professor **ptr1,struct student **ptr2,int size,int *head)
  {
      ...
      input(stack,ptr1,ptr2,size,head,&amp;a,&amp;b);
      ...
  }
  
  
  int input(void **stack,struct professor **ptr1,struct student **ptr2,int size,int *head,int *a,int *b)
  {
              ...
              done=Push(stack,head,(*(int *)ptr2+*a),size);
              (*ptr2+*a)=(struct student *)malloc(sizeof(struct student));
              stud_input(ptr2,a);
              ...
  }
  </code></pre>