0
'return' for main() termination
"return 0; This statement terminates the main() function and returns the value 0 to the calling process. The number 0 generally means that our program has successfully executed. Any other number indicates that the program has failed." Why does the program runs & executes, if we return some random no. like 'return 836' ? In this case, shouldn't we get some error or even a warning??
8 Respuestas
+ 3
You can return anything. The return of a fuction is like a result that the function gives. For example you can make a fuction that takes two numbers and returns their sum
int sum (a, b) {
return a+b;
}
+ 1
Thank You Coder Kitten , your example was really helpful,
thanks to you too Andrei I. 😊
0
Andrei I But thats for user defined functions, can we do this even for terminating main() function?
0
Yes, you can do it with every function including the main one
0
If you're still curious, try accessing a value of a null pointer.
E.g:
int *p = NULL;
printf ("%d\n", *p);
0
LastSecond959
I tried, it shows 'timeout',
for this code to work, *p should store some address, if the address is NULL like you mentioned, it cannot find any address and will give a "runtime error" .
btw, How is this suppose to help me with what I've asked in question??
0
Chinmoy Kumar Hansda It probably depends on where you type the code, I use DevC++ (PC) and it results with runtime error and return value of 3221225477.