Results 1 to 6 of 6

Thread: Pointers VS Arrays in C++

  1. #1
    Join Date
    Dec 2009
    Posts
    17

    Pointers VS Arrays in C++

    I am intermediate programmer in the programming world. It feels great to do programming. Right now, i am learning programming languages: Java, DBMS, Visual Basic, C++ and C sharp. I have got an project, in which i have use either pointers or indexes and i am confused which one to use. Which is more powerful pointer or arrays?? Please tell me which one should i choose.
    Last edited by Rum; 18-01-2010 at 01:10 PM.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Pointers VS Arrays in C++

    According to me, the function of arrays is very much similar/bound to the one of pointers. In fact, the identifier of the arrays is equivalent/same to the address of its first element, as a pointer is equivalent/same to the address of the first element that it points to, this is because i am telling that they both have same concept/function.
    Example of Arrays and Pointers:
    int num [30];
    int * num;

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Pointers VS Arrays in C++

    I would say that both Pointers and Arrays are two different things and think cannot be differentiated. Instead of this, i can say that array names can be sued as pointer and it is a const pointer also. In other words, an array name is actually a pointer to the first element of the array.
    Example:
    int a[50]; // a is an array of 50 ints.
    int* pt; // pt is a pointer to an int.
    pt = a; // Assigns the address of first element of a to pt.
    pt = &a[0]; // Exactly the same assignment as above.
    Hope you will be able to get enough knowledge about the pointers and arrays.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Pointers VS Arrays in C++

    I don't want what will be difference between the pointer and arrays, but surely can give some information about the pointers. Pointer is a variable which will store a memory address. Each and every variable is been located inside the unique location within a computers memory and this unique location is with its own unique address(i.e the memory address). Usually, the variables can hold values such as 7 or “HI” and these values are stored under specific location within computer memory. But pointer is a different beast, because it holds the value of its memory address and also has capability to 'point' ( i.e pointer ) to certain value within a memory, by use of its associated memory address.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Pointers VS Arrays in C++

    Arrays: In C++, arrays are one of the data structures which you can be used to store/place consecutive values of the same type of data types. Arrays in C++ can also be declared for all data types (i.e int, float, double, char, struct, char etc.) And all the values are stored in consecutive memory locations. The values can be accessed by using the position of the stored value.
    Pointers: It is a variable which will hold the addresses of another variables/functions/data. The pointer is told to be "point to" the memory address which is stored in it. Example:
    signed main()
    {
    int* pt;
    //Right now, pt contains no particular myval in this C++ code.
    }

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Pointers VS Arrays in C++

    I would say that the pointer can be referred to the individual item or to an arrays of items. In fact, the array is only the way of creating both the list of items and the pointers to that lists first item in one declaration. The array and pointer concepts are more or less completely interchangeable. In other words, we can say that subscripts can be useful with the pointers, as if they were arrays held at the address of the pointer. On the other hand, the array can also be used as if it was the pointer. The only difference between the pointers and arrays, is that the address of the array are not able to be changed by assignment.

Similar Threads

  1. What are the advantages of pointers?
    By Owen Fernandes in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 12:39 PM
  2. Pointers in C and C++
    By unlimitedtech in forum Guides & Tutorials
    Replies: 4
    Last Post: 04-02-2010, 12:42 PM
  3. Pointer to an array of pointers
    By pushpendra in forum Software Development
    Replies: 3
    Last Post: 29-12-2009, 12:45 PM
  4. Are pointers and arrays equivalent
    By KALINDA in forum Software Development
    Replies: 3
    Last Post: 16-10-2009, 06:41 PM
  5. Arrays and Pointers in C
    By Ivy00 in forum Software Development
    Replies: 1
    Last Post: 10-11-2008, 05:28 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,265,094.75383 seconds with 17 queries