Is it "good practice" to create a variable inside a function and giving a reference back?
Here is a minimal example:
#include <iostream>
int* add(int* a, int* b)
{
int c = *a + *b; // c is created here and a reference is given back
int* p_c;
p_c = &c;
}
main()
{
int a = 1;
int b = 2;
int* p_c = add(&a, &b);
std::cout << *p_c << std::endl;
}
In the main function *p_c gives me the correct value. However, the value is created in the fuction add. Is this causing problems?