+ 3

What is the meaning of ' return 0 ' and why it is used ??

1st Jul 2019, 3:58 AM
Npower Nks
Npower Nks - avatar
6 Respostas
+ 17
In every C program you have to use return return 0; (or return -1;, or whatever... ), because the main function signature requires it. In a C++ program the statement is optional: the compiler automatically adds a return 0; if you don't explicitely return a value. The return value is the exit code of your program, the shell (or any other application that ran it) can read and use it. The 0 exit code is a widely accepted convention for 'OK the program execution was successfull'.
1st Jul 2019, 4:01 AM
Shadow Ninja[#Inactive]
Shadow Ninja[#Inactive] - avatar
+ 9
'return 0' means that the function doesn't return any value. It is used when the void return type is used with the function. It is not mandatory to add a 'return 0' statement to the function which doesn't return any value, the compiler adds it virtually.
1st Jul 2019, 6:21 AM
Manoj
Manoj - avatar
+ 6
It actually depends on the return type of the function If main is declare as follows int main() Then here int is the return type and u should return some int And if declared void main() Then return is not required to be written in this
1st Jul 2019, 9:20 AM
Sharma Abhishek
 Sharma Abhishek  - avatar
+ 4
When we say return it is going to return some value( or void ) to the current function. There are 2 place we can see how return behaves 1. User function ( created inside a class ): When user created a function and return 0 which means during the function call the called function is going to return integer which is 0 . All the lines after the return 0 will not be executed a. examaple : int result = myfuc(); myfuc() { return 0 } -> result will be having value 0 2. main function: In c program we can see that main function return 0, why we should do that without any use is the big question. let me explain why , When the program gets executed in the memory main function will be called and loaded first instructions inside the main() will get executed once all line of code completes successfully then the program has to get released from memory. return 0 tells processor that program execution completed and can be released Part --1
2nd Jul 2019, 10:44 AM
Saurav Kashyap
Saurav Kashyap - avatar
+ 4
Part--2 2. main function: In c program we can see that main function return 0, why we should do that without any use is the big question. let me explain why , When the program gets executed in the memory main function will be called and loaded first instructions inside the main() will get executed once all line of code completes successfully then the program has to get released from memory. return 0 tells processor that program execution completed and can be released a. Still the doubt is even when we didn’t return it finish execution. This is because when the program completed execution return void will be executed automatically ( this will vary based on different compilers ) and terminates the program and through outside memory b. I would prefer to end program completion by myself and smoothly end the execution so I prefer to return 0 Hope u like it...!!
2nd Jul 2019, 10:45 AM
Saurav Kashyap
Saurav Kashyap - avatar
0
If you're in need of additional help with your math studies, online math tuition can be a great option. By working with a qualified math tutor, you can receive personalized instruction and support that can help you to better understand complex concepts, improve your problem-solving skills, and achieve your academic goals. One online math tuition provider you may want to consider is https://88guru.com/subject/online-maths-tuition
23rd Feb 2023, 8:55 AM
derik