I am trying to understand how malloc and pointer works.
#include <stdio.h>
#include <stdlib.h>
int main() {
    int *p;
    int b = 15;
    p = (int *)malloc(sizeof(int) * 10);
    for (int i = 0; i < 5; i++) {
        p + i = &b;
    }
}
The above code gives error expression is not assignable p + i = &b;
As far as I understand, malloc gives the starting address of the memory allocated in heap which I typecast to hold the address of integers. So technically, p + i should be able to hold any integer address, but the code throws an error. Can you please explain why this is wrong.
Thanks
 
     
    