The shared memory is just a big chunk of memory both processes can write to, like a piece of paper shared between two people. Both people need to know what is on each line of the paper. You start by putting select on "the first line", or right at the beginning of the block of shared memory. Your array a will start on "the second line". In your code, shared_memory, which is the value returned by shmat(), is the starting address of your block of shared memory. For example:
Code:
memcpy(shared_memory, &select, sizeof(select)); // store select at the beginning of shared_memory
memcpy(shared_memory + sizeof(select), a, sizeof(a)); // store a at the first spot after select