what does exit(10); mean in C language program?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bthakurwar
    New Member
    • Oct 2012
    • 2

    what does exit(10); mean in C language program?

    Code:
    #include<stdio.h>
    int main()
    {
     int j=printf("Hello.");
     return 0;
     exit(10);
    }
    Here in the above C program, what does exit(10) mean?
    Last edited by Rabbit; Oct 12 '12, 03:23 PM.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    it means exit the program and return a value of 10 to the operating system as the programs result.

    What 10 might mean is operating system dependant the only number with a defined meaning is 0 which must be interpreted as success. Normally any non-zero number is interpreted as fail in some manner.

    Comment

    • soli
      New Member
      • Nov 2011
      • 3

      #3
      I think "exit(10);" here is meaningless and unreachable, case the program return 0 before.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Sorry you're right I answered the question in your title not the question in your post.

        In the posted code the exit(10); is unreachable and will never be executed because the return 0; will happen first.

        Comment

        • Icyhot
          New Member
          • Oct 2012
          • 6

          #5
          Check this out for more details about the exit method.
          Last edited by Frinavale; Oct 25 '12, 02:02 PM. Reason: Added text to the link so that people know what the link is about.

          Comment

          • xrajaghosh
            New Member
            • Oct 2012
            • 1

            #6
            i think its meaningless it's same as exit(0),exit(1) ..if i m wrong then pls let me knw

            Comment

            • sonu53
              New Member
              • Oct 2012
              • 1

              #7
              at starting of prog. there is int j = (print"hello");
              here is i is of integer type and hello is of char type then how can it possible....??
              pls explain mi in detail this program from top to bottom.

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                @sonu, printf accepts a char* and returns an int. It's not returning the char* being passed to printf.

                Comment

                • Shubhangi24
                  New Member
                  • Oct 2012
                  • 20

                  #9
                  When return 0 will be encountered function returns to O.S. with value as 0. So the exit(10) will never be executed.

                  Comment

                  • Shubhangi24
                    New Member
                    • Oct 2012
                    • 20

                    #10
                    exit(10) i.e. any non zero value to exit() is considered as abnormal program termination.

                    Comment

                    • donbock
                      Recognized Expert Top Contributor
                      • Mar 2008
                      • 2427

                      #11
                      The exit value can be tested by the entity (batch script, perl script, make, etc) that invoked the program. The meaning of any particular exit value depends on the program that returns it; but the implication of the exit value depends on how the invoking entity reacts to it.

                      FYI, the default behavior for make is to abort the build if any program returns with a nonzero exit value.

                      If you write a program that supports nonzero exit values then it is may be useful to print an explanatory error message to stderr before exiting. Printing the error message may be unconditional or you might choose to print it only if a command-line argument requests verbose output. Refer to the perror function for a means to print errors reported by Standard Library functions.
                      Last edited by donbock; Oct 18 '12, 12:29 PM. Reason: Added paragraph about printing an error message.

                      Comment

                      • sgayathri2412
                        New Member
                        • Oct 2012
                        • 8

                        #12
                        Is the code correct?

                        Comment

                        Working...