Can this example be done with pointers instead of global variable?

Posted by Louise on Stack Overflow See other posts from Stack Overflow or by Louise
Published on 2010-06-12T20:01:14Z Indexed on 2010/06/12 20:02 UTC
Read the original article Hit count: 214

Filed under:
|

This is a simplified example of the problem I have:

#include <stdio.h>
#include <stdlib.h>

void f2(int** a) {
  printf("a: %i\n", **a);
}

void f1(int* a) {
  f2(&a);
}

int main() {
  int a = 3;
  f1(&a); // prints "a: 3"

  f2(???);

  return 0;
}

The problem is that I would like to be able to use f2() both in main() and in f1().

Can that be done without using global variables?

© Stack Overflow or respective owner

Related posts about c++

Related posts about c