HELP! im looking for different ways .

This is a discussion on HELP! im looking for different ways . within the C++ Programming forums, part of the General Programming Boards category; Im looking for ways to use arrays using pointers. an ex is: #include<iostream.h> #include<conio.h> void main () { int sales[7]= ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    9

    Exclamation HELP! im looking for different ways .

    Im looking for ways to use arrays using pointers.
    an ex is:
    #include<iostream.h>
    #include<conio.h>
    void main ()
    {
    int sales[7]= {1,2,3,4,5,6,7}
    int*p=&sales[0];
    int x;
    //-----------------------------
    for(x=0; x<7; ++x)
    cout<<"$"<<sales[x]<<" ";
    cout<<endl;
    //-----------------------------
    for(x=0; x<7; ++x)
    cout<<"$"<<p[x]<<" ";
    cout<<endl;
    //-----------------------------
    for(x=0; x<7; ++x)
    cout<<"$"<<*(sales+x<<" ";
    cout<<endl;
    //-----------------------------
    for(x=0; x<7; ++x)
    cout<<"$"<<*(p+x)<< " ";
    cout<<endl;
    getch();
    }

    \\ all of the above give the same result
    \\$1 $2 $3 $4 $5 $6 $7

    any more ways???????
    at least I need 10 more ways

    any feed back is greatly accepted
    Last edited by moenia; 04-29-2002 at 02:11 PM.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    206

    Re: HELP! im looking for different ways .

    Originally posted by moenia
    Im looking for ways to use arrays using pointers.
    an ex is:
    int num[5]={2,6,9,2,2};
    int*ptr;
    ptr=num;
    ptr=&num[0]



    any feed back is greatly accepted
    congrats, you just ruined your pointer.

    Code:
    int num[5] = {2, 6, 9, 2, 2};
    int *ptr = num[1];
    cout<<ptr;
    output :
    Code:
    6

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    using & means its appointed to a reference so:

    &num = numb;

    would not make &num = numb, it would just replace it when it comes up in the program so:

    cout<<&num;

    would display numb and not &num

    cout<<num;

    would display the address of the variable numb
    ex:
    output : Ax00A4b00

    (maybe its not a real address i dunno but it looks kinda like that)

    dont try modifying addresses cause u could mess up your computer -_-'

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. any smarter ways to design this tree structure
    By George2 in forum C++ Programming
    Replies: 5
    Last Post: 04-19-2008, 08:34 AM
  2. Smarter ways to define MACRO to strings?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 11-22-2007, 02:05 AM
  3. Best ways to learn
    By MartijnG in forum C++ Programming
    Replies: 15
    Last Post: 08-29-2006, 11:51 AM
  4. Three ways to get creation date of a file?!
    By maxhavoc in forum Windows Programming
    Replies: 1
    Last Post: 01-08-2005, 02:16 PM
  5. Easy painless ways to code
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 12-31-2003, 10:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21