Why Return 0 is used in C

Return 0 :

Return 0 in C signifies that the program has been implemented successfully, allowing the processor to be uploaded. Because the return void command would be executed right away when the program’s implementation was terminated

Return 0

Why Return 0 ?  :

  • Since the main function (int main()) returns a numeric number, we are return 0.When a function returns a result, the word “return” is used.
  • As a result, we may utilise the return statement to conclude the main function because the program has been correctly completed.When the primary function’s data type is “integer,” it must provide a result.
  • Therefore, we just use return 0.The primary function will be of data type “void,” hence nothing will need to be provided.The return value is the program’s exit code.

Examples of Return 0 :  :

Let,s see some example for better understanding :

Example 1:

Run
#include<stdio.h>
int main() {
   int val1 = 20;
   
   printf("val1 : %d\n",val1);
    return 0;
}

Output :
val1 : 20

Example 2  :

 

Run
#include<stdio.h>  
int *help(){  
    int val = 20;  
    return &val;  
 }  
int main() {  
    int *ptr = help();  
    printf("%d", *ptr);  
    return 0;  
}  

Output :
Segmentation fault

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription