calling functions: exit and return

This is a discussion on calling functions: exit and return within the C Programming forums, part of the General Programming Boards category; In C program I have a function: Code: void eg1() { if (i==1){ exit(1) } } main(){ eg1(); } Return ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    23

    calling functions: exit and return

    In C program I have a function:
    Code:
    void eg1()
    {
    	if (i==1){
    		exit(1)
    	}
    }
    
    main(){
    
    eg1();
    
    }
    Return type of eg1 is void, so does it make sense/valid to do exit(1) inside it. If there is a faliure in eg1, then it will come back to main immediately or the whole progam stops? Also, exit(1) and return 1; are same thing?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Return type of eg1 is void, so does it make sense/valid to do exit(1) inside it.
    Yes, exit doesn't apply to the current function, it applies to the running program as a whole. Saying exit(1) from any function is equivalent to saying return 1 from main.
    My best code is written with the delete key.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    main() should return int explicitly.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  2. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21