Thread: Pointers

  1. #1
    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,218
    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
    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, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM