Your code invokes undefined behavior because the pointer was left uninitialized. You need to initialize the pointer first before inserting into it anything:
int *ptr = malloc(sizeof(int) * REQ_SIZE);
After this, you will no longer get a segfault. Note that you need to put a dereference operator instead of &
to print the containing value of the integer pointer.
Here's a demo.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…