-
some of you might have already realized it, but http://www.cprogramming.com/advtutorial.html has some good tutorials about C++ programming. Also, nebulus, i dont quite understand what you are saying. I am pretty sure that if i create a code in C++ it will not compile:
#include <iostream>
using namespace std;
int function()
{
int j,k,l;
int *ptr_pointer;
j=1;
k=2;
l=0;
ptr_pointer = j + k;
return ptr_pointer;
}
int main ()
{
int x=0;
x=function();
cout << x;
}
again i didnt compile this and i didnt think at all when i wrote this in here, so there might be errors. Anyways, the value of x will not equal 3...right?
-
It wouldn't work because you are trying to assign integers to pointers.
#include <iostream>
int *function(int i)
{
int j = 1;
int k = 2;
int l = 0;
l = i + j + k;
return &l;
}
int main()
{
int *x;
x = funtion(2);
cout << x;
}
Should print out 5.
It might require monkeying around, but you have to careful that you are returning things that make sense...you were trying to return a pointer and then assign to an int, god only knows what you would get. And by the way, this application is pretty pointless. It is more useful once you start using struct's or C++ objects.
/nebulus
-
now i understand what you are saying...ok, but still lol sorry this is taking forever, the return type cannot be a pointer... or can it because right now your are just returning the address of a variable ( return &l; ) Thanks for the explination