Are there any problems with this code
Jan 17, 2013 at 5:17am UTC
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 Jan 17, 2013 at 5:18am UTC
Jan 17, 2013 at 5:56am UTC
VectorMath.hpp - Don't have it. (Changed it to <cstdio> and worked fine.)
Last edited on Jan 17, 2013 at 5:57am UTC
Jan 17, 2013 at 6:39am UTC
a ceases to exist when foo returns, so dereferencing b in main is undefined behavior.
Topic archived. No new replies allowed.