View Poll Results: When should C++ be taught

Voters

9. You may not vote on this poll

High School

777.78%

Before College

111.11%

During College

111.11%

Post College Education

00%

Need help with pointers

This is a discussion on Need help with pointers within the C++ Programming forums, part of the General Programming Boards category; I need help in understanding how to use/write a pointer. I am only a junior and i have been told ...

Need help with pointers

I need help in understanding how to use/write a pointer. I am only a junior and i have been told this class should not be taught to HS Students and i am lost, in it, and i can't drop the class, whats a girl to do?

yes

some people think, when they they first learn pointers, "what will i ever need this for in c++?". Thats what I first thought. First, you will need them because other concepts taught in c++ have pointers, so they are a must. Second of all, to change the values of variables without creating an extra variable, you need to pass pointers to the function. Pointers are simple to understand. First of all, they of course point to the address of a variable or function mainly. You declare it like this: int* ptr; You need the asterisk after the variable type. Now, if you want to change whats in the address, you write something like this: ptr++. It increments the address by 1. If it was pointing to an array: ptr=array[1]; Then: ptr++; will make it point to the third element of the array, or array[2]. Also you can change the value of what is in the pointer like this: *ptr++; that will increment the value of whats in the pointer by 1. Blah blah, that enough or you need more?

QUESTION: Which values are stored in XYZ.nonsense1, XYZ.nonsense2, ABC.nonsense1, ABC.nonsense2 after the calls to dononsense?
(to do less nonsense you may need to know the this-pointer and its use; however, finding the correct answers would prove you're an expert on pointers.)

Pointers are pretty straightforward until you get into multiple indirection. Then they can become a little harder, but not much.

Pointers do exactly that - point at something. They point at memory addresses - you could think of as though they point to one little mailbox in a huge grid of mailboxes. The value at an address would be what's in the mailbox. The address of the mailbox is where the mailbox is.

This stuff really should be taught in High School in order to prepare students for the everchanging everexpanding world of computers. If I had learned this in high school, I would be much farther along than I am. It is a shame that most have to wait until college to learn C/C++. My opinion is that you will learn more on your own, but school will get you into some very good habits and will teach you good program structure (hopefully).

Create some integer pointers and use printf("%p",yourptr) to see it's address and printf("%d",*yourptr) to see what it's value is or what's in it's mailbox.