In following case I get NumRecPrinted = 0 , that is num is 0
int main()
{
int demo(int *NumRecPrinted);
int num = 0;
demo(&num);
cout << "NumRecPrinted=" << num; <<<< Prints 0
return 0;
}
int demo (int *NumRecPrinted)
{
int no_of_records = 11;
NumRecPrinted = &no_of_records;
}
You are assigning the address to the pointer, and not the value to the pointed-to. Try it like this instead