Thread: Does C also have reference parameters

  1. #1
    Registered User
    Join Date
    Mar 2010

    Does C also have reference parameters

    For example:

    int a = 5;
    int &b = a;

    b and a are both 6


  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Use a const pointer, e.g.,
    int a = 5;
    int *const b = &a;
    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

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    C does not have references and probably never will. It's that kind of language.
    But fret not, it has and always will have pointers which can do everything references can and more, albeit in a slightly more complicated way.
    Last edited by Elysia; 09-28-2010 at 01:14 AM.
    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.

  4. #4
    C lover
    Join Date
    Oct 2007
    Heh, they(pointers) could be a headache if stuff like this was abused:

    int value = 5;
    int *foo = &value;
    int **bar = &foo;
    int ***baz = &bar
    // Or how about 
    int ******ptr;
    Heh, ptr is also valid

    But for the sake of being on topic, as Elysia has already said, C has pointers and pass by value. No pass by reference like in C++

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined reference
    By TheEngineer in forum C Programming
    Replies: 17
    Last Post: 08-12-2009, 10:34 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. reference parameters
    By LowLife in forum C Programming
    Replies: 8
    Last Post: 01-25-2006, 11:50 AM
  4. Reference parameters and calculating change
    By Cstudent2121 in forum C Programming
    Replies: 6
    Last Post: 11-04-2005, 03:19 PM
  5. Passing parameters by reference
    By aker_y3k in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2003, 06:46 PM