Pointers

This is a discussion on Pointers within the C Programming forums, part of the General Programming Boards category; I haven't used C in forever, and I can't remember how to change the value of a variable in main ...

  1. #1
    EKO
    EKO is offline
    Registered User
    Join Date
    May 2005
    Posts
    2

    Pointers

    I haven't used C in forever, and I can't remember how to change the value of a variable in main using a function. I have something that looks like the following, but the values never change:

    Code:
    void function(int, int *, int *...);
    void main()
    {
        int a, b=0, c=0...;
        .
        .
        .
        function(a, &b, &c...);
    }
    
    void function(int aa, int *bb, int *cc...)
    {
        if (aa==1)
            *bb++;
    }
    I put a printf under the if statement in function, and it prints, but the value of b never changes.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,167
    Be careful of operator precedence.

    *b++ = *(b++), not (*b)++ which is what you want.
    If you understand what you're doing, you're not learning anything.

  3. #3
    EKO
    EKO is offline
    Registered User
    Join Date
    May 2005
    Posts
    2
    Thanks! Works just fine now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM

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