Thread: return 0; vs return (0);

  1. #1
    Unregistered
    Guest

    return 0; vs return (0);

    see the subject! wich is more proper/better c++ style?

  2. #2
    Unregistered
    Guest
    return 0;

    It's all I've ever seen, anyway.

  3. #3
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    It helps readability to surround the return value with the (). It's not much if it's a constant (0, 1) but it does help when you're returning the value of a function or equation.

  4. #4
    Unregistered
    Guest
    agreed

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Either one works, it's a matter of personal preference since returning a simple value is easy to read anyway. Now, if you had something like
    return i * j / c;
    it wouldn't hurt to say
    return ( i * j / c );

    For simple return types such as 0 for a success and 1 for a failure I prefer to use the constants
    return EXIT_SUCCESS;
    and
    return EXIT_FAILURE;
    for added clarity.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  3. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM
  4. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM
  5. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 01:54 AM