-
February 5th, 2013, 09:19 PM
#1
C++ Pointer Help
I'm trying to figure out the value of pointers after the following code snippet
Code:
int s[8] ;
int *iptr1, *iptr2 ;
int **iptr3 ;
for (int i = 0 ; i < 8 ; i++)
s[i] = 7 - i ;
iptr1 = s ;
iptr2 = &s[3] ;
iptr3 = &iptr1 ;
*iptr1 = 5 ;
*iptr2 = 11 ;
**iptr3 = 14 ;
I neeed to find what the value of iptr1, iptr2, and iptr3 are after the code is executed. I'm having trouble understanding how pointers work, so any clarity on this would be appreciated. Thanks.
-
February 6th, 2013, 04:44 AM
#2
Re: C++ Pointer Help
Originally Posted by kpb17
I neeed to find what the value of iptr1, iptr2, and iptr3 are after the code is executed. I'm having trouble understanding how pointers work, so any clarity on this would be appreciated. Thanks.
Why don't you give it a shot yourself first? Explain what you think each line means and what the value of each variable is. Then we'll tell you if it's correct and give you further advice.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
February 6th, 2013, 08:22 AM
#3
Re: C++ Pointer Help
Or, you could write a program and see what it does.
-
February 6th, 2013, 08:48 AM
#4
Re: C++ Pointer Help
Or, you could write a program and see what it does.
and step through the program using the debugger so that you can see the changes as they happen. Then hopefully you'll understand.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|