View Single Post
  #10   Spotlight this post!  
Unread 13-12-2007, 02:23
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,186
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: How to manipulate a variable value using an array?

Quote:
Originally Posted by amateurrobotguy View Post

I don't get some of your example:

Code:
void idouble(int * input){  Input the address and convert it to the data "input"
   *input *= 2 ; I don't get the use of *input
}

void main(){
    int x ;
    x = 5 ;
    idouble(&x) ;  Call the above function giving it an address as a parameter
    print(x); I don't get how the idouble() returns x
}
input is a pointer. it holds an address. in this particular case, it holds the address of x. putting a * in front of a pointer means that you want to look at the value held at the address of the pointer. if input = &x, *input = x. so modifying *input will actually be modifying the value held in x. (input is a pointer, so it has no real value attached to it.) By doing this, you can modify variables in your main function without returning ANYTHING from a called function. idouble returns nothing, but because you are telling it where x is in memory and not just the value of x, you can actually change x from another function. Make sense?