Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , ,

Sponsored Links


Pointers VS Arrays in C++

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 18-01-2010
Rum Rum is offline
Member
 
Join Date: Dec 2009
Posts: 17
Pointers VS Arrays in C++

Sponsored Links
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 12:10 PM.
Reply With Quote
  #2  
Old 18-01-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,943
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;
Reply With Quote
  #3  
Old 18-01-2010
Member
 
Join Date: May 2008
Posts: 2,000
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.
Reply With Quote
  #4  
Old 18-01-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,989
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.
Reply With Quote
  #5  
Old 18-01-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,278
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.
}
Reply With Quote
  #6  
Old 18-01-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,381
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Pointers VS Arrays in C++"
Thread Thread Starter Forum Replies Last Post
What are the advantages of pointers? Owen Fernandes Software Development 5 09-02-2010 11:39 AM
Pointers in C and C++ unlimitedtech Guides & Tutorials 4 04-02-2010 11:42 AM
Pointer to an array of pointers pushpendra Software Development 3 29-12-2009 11:45 AM
Are pointers and arrays equivalent KALINDA Software Development 3 16-10-2009 06:41 PM
Arrays and Pointers in C Ivy00 Software Development 1 10-11-2008 04:28 PM


All times are GMT +5.5. The time now is 02:20 AM.