I have a small but confusing problem... First question is what is the use of main.I know the question is silly and simple but i have a problem.I have written a code
#include<unistd.h>
#include<sys/types.h>
#include<stdio.h>
int main(){
pid_t ty;
ty=fork();
if(ty==0){
const char* x="/home/brucewilson/Desktop/jack_sahoo_teja_CDP/hey2";
static char *argv[]={"echo","Foo is my name.",NULL};
int main(){//observe this is second main in my child process
printf("hello");
}
int add(){
printf("5");
}
main();
add();
}
}`
Did you observe the second main function i used in my child process well the compiler gave me no error for this..Added to this it gave me the output as "hello" and 5.
And obviously the below code would give an error...
int main(){
printf("main");
main();
}
int main(){
}
So my question is why did it work for the child process?So is the notion that im assuming to be true that is no function can be named main() and every child process will have a main function shared from its parent is false.Please explain me what is going underneath this code inside my system because the child process assumes main just as another function and it doesnot need a main function also.Then how will the child process know from where should it start?