How does exit(0) in child process work?

#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include <sys/wait.h>

int main() {

pid_t pid;
int num_coconuts = 17;
pid = fork();

if(pid == 0) {
    num_coconuts = 42;
    exit(0);
} else {
wait(NULL); /*wait until the child terminates */

}

printf("I see %d coconuts!\n", num_coconuts);
exit(0);

}
What do the program display on the screen ? Why ?
Obvious,I run the program and know the result
The output is : I see 17 coconuts
But when I delete exit(0) in the if statement, the output is : I see 42
coconuts I see 17 coconuts
So,my question is how exit(0) effects to the child and parent process ?

https://linux.die.net/man/2/fork

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?