Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualLarsDC

Posted 01 September 2012 - 04:16 PM

In your response I want 2 answers from you:
Could you explain me, in a neat/technical sentence, how a pointer works?
Could you explain me what the difference is between a local, global, member variable? Also in in neat sentence.


I'm not him but I couldn't resist this little challenge. Always fun to see if I've listened closely enough during my school lessons.
Actually created a user here on the awesome GD.net to post this Posted Image

Pointer: A pointer work in the way that it gives you direct access to the memorybank/memoryspace in which a variable is stored on your computer. Meaning the chunk of memory that is reserved for this variable. Meaning if you forget to *pointer=0 before reassigned it another value you will create memory leaks as the memorybank is still "locked".

Variables:
Local - Local variables are variables accessible by all functions within the class where it is created.
Example:
int main{
int a;
}
//Destroyed when the block/function/class ends

Member - Member variables are only accessible within the scope where they are created meaning inside a function for instance
Example:
int main{
void randomName(){
int a;
}
}
//Destroyed when the block/function ends

Global - Global variables are accessible from everywhere in your program, hence the name global.
Example:

int a;
int main(){
}
//Destroyed when the program terminates


Wow that was more than a sentence, sorry.

Of course I would appriciate it a lot if you would confirm if I have indeed been listening or need to redo my last semester ;)

You are of course welcome to PM me the answer as to not spoil it completely.

And sorry for hijacking/butting in on the post Posted Image

#1LarsDC

Posted 01 September 2012 - 04:15 PM

In your response I want 2 answers from you:
Could you explain me, in a neat/technical sentence, how a pointer works?
Could you explain me what the difference is between a local, global, member variable? Also in in neat sentence.


I'm not him but I couldn't resist this little challenge. Always fun to see if I've listened closely enough during my school lessons.
Actually created a user here on the awesome GD.net to post this :P

Pointer: A pointer work in the way that it gives you direct access to the memorybank/memoryspace in which a variable is stored on your computer. Meaning the chunk of memory that is reserved for this variable. Meaning if you forget to *pointer=0 before reassigned it another value you will create memory leaks as the memorybank is still "locked".

Variables:
Local - Local variables are variables accessible by all functions within the class where it is created.
Example:
int main{
int a;
}
//Destroyed when the block/function/class ends

Member - Member variables are only accessible within the scope where they are created meaning inside a function for instance
Example:
int main{
void randomName(){
int a;
}
}
//Destroyed when the block/function ends

Global - Global variables are accessible from everywhere in your program, hence the name global.
Example:

int a;
int main(){
}
//Destroyed when the program terminates


Wow that was more than a sentence, sorry.

Of course I would appriciate it a lot if you would confirm if I have indeed been listening or need to redo my last semester ;)

You are of course welcome to PM me the answer as to not spoil it completely.

And sorry for hijacking/butting in on the post :)

PARTNERS