Thread: pointers and function calls inside a function

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    7

    pointers and function calls inside a function

    Hello, I have a problem I am trying to figure out. I have a variable a in main. I am passing the address of this variable to my function foo.
    Code:
    int main() {
    int a = 0;
    
    foo(&a);
    
    }
    
    void foo(int * a);
    in my function foo, I would like to do the same thing to this variable within my function foo, passing it to my function foo2.

    Code:
    void foo(int * a) {
       
       foo2(&(*a));
    
    }
    
    void foo2(int * a) {
    
       int x = *a;
    
    }
    would that be a proper call, parameter list and use of the variable in my function? thank you.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Actually since a inside foo is already a pointer you could just pass it along as foo2(a);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointers and Function calls
    By Michele Degges in forum C Programming
    Replies: 1
    Last Post: 10-09-2011, 02:46 PM
  2. Replies: 19
    Last Post: 09-08-2011, 07:56 AM
  3. Replies: 17
    Last Post: 07-06-2011, 11:44 AM
  4. function calls and pointers
    By davidjg in forum C Programming
    Replies: 14
    Last Post: 01-30-2011, 11:40 PM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM