• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
KittensWithSpikes

understanding pointers

6 posts in this topic

Hi, I'm a new user at gamedev.net but I've known about the site for a long time .

so im new to c++ but not new to programming i have program for a while in c#.

so I've been watching the software engineering videos at 3d buzz and just wanted to make sure i understand pointers before i continue on.

here's my code with comments on what i comprehended :

[code]
]#include <iostream>

using namespace std;

int main()
{
int *ptr; // initialize a pointer ptr of type int
int x = 3; // initialize a variable X of type int to 3
ptr = &x; // get the memory address of X by referencing it and assigning it to ptr

cout << "&ptr = " << &ptr << endl; // prints out the memory address of ptr
cout << "ptr = " << ptr << endl; // prints out ptr which has the memory address of X
cout << "&x = " << &x << endl; // prints out the memory address of X
cout << "x = " << x << endl; // prints the value of X
cout << "*ptr = " << *ptr << endl; // prints the dereference ptr which has the value of X
cout << endl;

int y = 23; // initialize a variable y of type int to 23
ptr = &y; // get the memory address of Y by referencing it and assigning it to ptr
int **dptr = &ptr; // declare a double pointer dptr and assign the memory address of ptr

cout << "&ptr = " << &ptr << endl; // prints out the memory address of ptr
cout << "ptr = " << ptr << endl; // prints out ptr which has the memory address of Y
cout << "&y = " << &y << endl; // prints out the memory address of Y
cout << "y = " << y << endl; // prints the value of Y
cout << "*ptr = " << *ptr << endl; // prints the dereference ptr which has the value of Y
cout << "dptr = " << dptr << endl; // prints out dptr which has the memory address of ptr
cout << "*dptr = " << *dptr << endl; // prints the dereference dptr which has the memory address of Y assigned to it

cout << "**dptr = " << **dptr << endl; // // prints the second(not sure of the word here) dereference of dptr which has the of Y

/* so basically what i gathered is when you have a & in front of a variable or pointer you get the memory address as the value.

when you have a pointer with a & and assign the reference of a variable the pointer now holds the memory address of said variable.

when we have a pointer without any * or & we get the memory address of the variable it was referencing.

when you dereference a pointer with * you are gaining the value of said variable that was referenced.

note:

i like to think of dereferencing as decrypting the memory address to gain access to the value of the variable (not sure if that analogy is correct).

when we have a double pointer (A) and assigning a reference to an other pointer(B) and just use the pointer(A) without any * or & we get the memory address of pointer(B) assigned into Pointer(A).

when we dereference it once we get the memory address of the variable that pointer(B) was pointing to and assign it into Pointer(A).

when we have a double dereference we get the value of the variable that pointer(B) was pointing to and assign itinto Pointer(A). */

return 0;[/code]
}

so yes i know this may be a long read for some of you .

please let me know if I'm not correct or misunderstanding .

also i know that when reading it may sometimes that i have broken sentences as I'm not a good writer i tried to re-read everything to make sure its clear so if something is not clear let me know.

thank you for your time and help, its much appreciated.
0

Share this post


Link to post
Share on other sites
[quote name='PrestoChung' timestamp='1295224380' post='4759866']
After reading through the code I don't notice any errors :)
[/quote]

i know their inst any errors just wanted to know if my understanding was correct of how pointers work

but thanks anyways
0

Share this post


Link to post
Share on other sites
[quote name='PrestoChung' timestamp='1295226835' post='4759877']
Right, I meant I don't see any errors with your reasoning, the comments describe accurately what is happening.
[/quote]

oh thanks i though u meant errors in code

thanks i really appreciate it
0

Share this post


Link to post
Share on other sites
Please note that this forum is not a chat room. Type properly, including correct spelling, grammar and punctuation. Take your time, there is no rush. We don't expect 100% accuracy, no one can, but please make a general effort. Programmers in particular should pay attention to getting these right, the compiler will not forgive you if you omit semicolons or use different spellings for identifiers. Note that your signature contains a (repeated) spelling error, the quote is "evidence of[b] absence[/b]", not "[b]absents[/b]".
1

Share this post


Link to post
Share on other sites
It really bothers me that this is how classes teach pointers. Pointers are one of the hardest things for a new programmer (along with recursion). Write a linked list. Then write a tree. You'll understand pointers and recursion way better than the code you wrote, which makes pointers seem confusing and, ahem, pointless. I've been programming for 10 years and I've never used a pointer to an integer (excluding arrays of course)

EDIT: oh, and I [url="http://lesswrong.com/lw/ih/absence_of_evidence_is_evidence_of_absence/"]disagree with your sig[/url] :)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0