C++ Pointer Help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: C++ Pointer Help

  1. #1
    Join Date
    Feb 2013
    Posts
    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.

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,016

    Re: C++ Pointer Help

    Quote Originally Posted by kpb17 View Post
    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

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,231

    Re: C++ Pointer Help

    Or, you could write a program and see what it does.

  4. #4
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,861

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center