some basic points about user-defined functions

This is a discussion on some basic points about user-defined functions within the C++ Programming forums, part of the General Programming Boards category; Hi 1: Someone was saying that in a return type user-defined function (which returns a value) one has to have ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    254

    some basic points about user-defined functions

    Hi

    1: Someone was saying that in a return type user-defined function (which returns a value) one has to have same data type of return value as the declared type of arguments. I think this is absolutely wrong. Because you could have different data types for arguments, further you could have totally different data type for return value. For example,
    Code:
    bool func(int dummya, float dummyb, long dummyc)
    is completely valid function in my view. Please confirm this for me. Thanks.

    2: Other point that someone was making about, I think, functions which don't take arguments. Perhaps, he was saying that in such functions you can cout and cin operators, but this is not possible for functions which take arguments. Perhaps, you could make some sense out of it! Please let me know what point was being made if you understand it. Thank you.

    Best wishes
    Jackson
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  2. #2
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    1) Correct, you can return any type you want from a function regardless of parameters.

    2) You can use cin and cout wherever you want as long as you have iostream included in the source file and the syntax is correct.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    > 1: Someone was saying that in a return type user-defined function ...
    That's easy, just stop listening to them from now on - they're completely ignorant and have nothing useful to say about C++ or programming.
    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
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by ~Kyo~ View Post
    2) You can use cin and cout wherever you want as long as you have iostream included in the source file and the syntax is correct.
    AND you are working in console mode.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,002
    To be pedantic, that's not true. You can use them. They just might not do any good.
    But then again, they go via the standard input/output which can be redirected to, say, files.
    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.

  6. #6
    Registered User
    Join Date
    May 2011
    Posts
    30
    Quote Originally Posted by CommonTater View Post
    AND you are working in console mode.
    It's still useful to check the text files from standard input in GUI mode.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. User-defined functions
    By naya22 in forum C++ Programming
    Replies: 6
    Last Post: 04-10-2007, 12:25 PM
  2. User defined functions
    By alexpos in forum C Programming
    Replies: 2
    Last Post: 10-23-2005, 03:53 PM
  3. New to user defined functions
    By Extropian in forum C Programming
    Replies: 4
    Last Post: 08-15-2005, 11:45 PM
  4. user-defined functions
    By MyntiFresh in forum C++ Programming
    Replies: 22
    Last Post: 07-10-2005, 02:11 PM
  5. Help! User defined functions
    By AdrenalinFlow in forum C Programming
    Replies: 3
    Last Post: 02-22-2003, 07:36 PM

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