No, that won't work. When you call fork(), you create a new process with its own heap, thus sharedMem is a different memory location for parent and child. If the child writes something to sharedMem, the parent process won't be able to access it (or vice versa).
You need a special syscall for IPC through shared memory; on Linux, that's mmap or shmget. One of the first Google results for how to use them gives an example: