Thread: int first(int & value) {} type function definition

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    36

    int first(int & value) {} type function definition

    if a function is defined as
    Code:
    int first(int & value) {}
    what does it mean? A function that accepts memory address should be defined as first(int * value) and when calling the function it should be called as first(&var_name) But what does the above function definition mean?

    Thanks

  2. #2
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    value is passed as a reference, from what I understand it's basically the same thing as a pointer argument, except that when you use pass by reference, you don't need to dereference inside the function definition.

    7.3 — Passing arguments by reference « Learn C++

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    36
    Thank you very much for that helpful post
    however I still don't exactly understand the difference between declaring func(int &var) and func(int *var)
    Is it that declaring *var passes address of function by value and &var doesn't?
    Or did I understand it wrongly?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What book are you using to learn C++. You should eventually reach the section where they explain C++ references to you.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    You can't learn the language asking questions piecemeal. Get a decent book and work your way through it.

  6. #6
    Registered User
    Join Date
    Dec 2011
    Posts
    36
    ok Thank you very much
    PS: How do I edit a previous post here (I mean an old one and not just the latest one) or how do I mark my thread as solved?
    Last edited by mahaju; 01-08-2012 at 10:52 PM. Reason: needed extra info

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You can't edit old posts after a certain time interval. This is to stop newbies editing out their entire source code after they get their answers.
    You can't mark threads as solved. There simply isn't such a feature, for good or for bad.
    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.

  8. #8
    Registered User
    Join Date
    Dec 2011
    Posts
    36
    I just wanted to know if there is a way to edit the title of the thread to say "solved"

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    There isn't, but you can ask a moderator to do it for you.
    Alternatively, if you really think such a feature is warranted, you can always suggest it to be added to the board. Just post in general discussion or PM webmaster.
    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.

  10. #10
    Registered User
    Join Date
    Dec 2011
    Posts
    36
    Quote Originally Posted by Elysia View Post
    There isn't, but you can ask a moderator to do it for you.
    Alternatively, if you really think such a feature is warranted, you can always suggest it to be added to the board. Just post in general discussion or PM webmaster.
    That's true, but I am sure the webmasters must have had their reasons for not implementing it yet

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You never know. Webmaster might just not have thought about it and it hasn't been requested by any board members. It never hurts to ask.
    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.

  12. #12
    Registered User
    Join Date
    Dec 2011
    Posts
    36
    You really think so?
    If so I request the moderators to suggest the webmaster that a feature to allow the starter to mark the thread as solved be added

    I am sure the moderators probably read all the posts so this should not go unnoticed

    By the way, you're wouldn't happen to be a moderator would you?
    Just checking

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You don't need to contact moderators to do that. You'd contact webmaster.
    Nope, not a moderator
    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.

  14. #14
    Registered User
    Join Date
    Dec 2011
    Posts
    36
    you know what, I think a moderator will probably lock this thread anyway because it is going way off topic
    So this will be my last post here
    By the way, thanks to everyone for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. missing type definition
    By roshni in forum C Programming
    Replies: 2
    Last Post: 06-17-2011, 08:13 AM
  2. confused with new type of int definition
    By devilofwar in forum C Programming
    Replies: 2
    Last Post: 12-07-2010, 03:39 PM
  3. Type definition issues?
    By FlyingIsFun1217 in forum C++ Programming
    Replies: 1
    Last Post: 07-05-2010, 07:17 PM
  4. function definition return type?
    By kes103 in forum C++ Programming
    Replies: 2
    Last Post: 08-15-2003, 07:47 PM