Are there any problems with this code

Sorry about asking but I want to be sure this is a legitimate way to pass variables. (I'm passing a reference of a to b) I don't think I have to deallocate anything or anything like that but I'm just wondering. Thanks!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//
//  main.cpp
//  test
//
//  Created by Temp on 1/14/13.
//  Copyright (c) 2013 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include "VectorMath.hpp"

void foo(int** i)
{
    int a = 5;
    *i=&a;
}

int main(int argc, const char * argv[])
{

    // insert code here...
    int *b = NULL;
    
    foo(&b);
    
    printf("%i",*b);
    
    return 0;
}
Last edited on
VectorMath.hpp - Don't have it. (Changed it to <cstdio> and worked fine.)
Last edited on
a ceases to exist when foo returns, so dereferencing b in main is undefined behavior.



Topic archived. No new replies allowed.