hi i was studying pointers references and came across different ways to feed in parameters. Can someone explain what each one actually means?
I think the first one is simple, its that x is a copy of the parameter fed in so another variable is created on the stack. as for the other im clueless.
void doSomething1(int x){
//code
}
void doSomething2(int *x){
//code
}
void doSomething3(int &x){
//code
}
void doSomething3(int const &x){
//code
}
I also see stuff like this when variables are declared. I don't understand the differences between them. I know that the first one will put 100 into the variable y on the stack. it wont create a new address or anything.
//example 1
int y = 100;
//example 2
int *y = 100;
//Example 3: epic confusion!
int *y = &z;
Question1: How do i use these methods? when is it most appropriate. Question2: When do I declare variables in that way?
examples would be great.
P.S. this is one the main reasons i didnt learn C++ as java just has garbage collection. but now i have to get into c++.