Does C also have reference parameters

This is a discussion on Does C also have reference parameters within the C Programming forums, part of the General Programming Boards category; For example: int a = 5; int &b = a; ++b; b and a are both 6 Greetings...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    44

    Does C also have reference parameters

    For example:

    int a = 5;
    int &b = a;
    ++b;

    b and a are both 6

    Greetings

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,886
    Use a const pointer, e.g.,
    Code:
    int a = 5;
    int *const b = &a;
    ++(*b);
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,765
    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
    Location
    Virginia
    Posts
    265
    Heh, they(pointers) could be a headache if stuff like this was abused:

    Code:
    int value = 5;
    int *foo = &value;
    int **bar = &foo;
    int ***baz = &bar
    // Or how about 
    int ******ptr;
    
    printf("%d",***baz);
    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, 10:50 AM
  4. Reference parameters and calculating change
    By Cstudent2121 in forum C Programming
    Replies: 6
    Last Post: 11-04-2005, 02:19 PM
  5. Passing parameters by reference
    By aker_y3k in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2003, 05:46 PM

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