|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
An array is a vector of values. A pointer is something that refers to a different part of memory (usually dynamically allocated memory but not always). They are totally different things in concept. As it is, arrays are implemented as pointers in C (the pointer is to the first array element). There are no performance benefits to using one over the other because the one is a special case of the other in C (but not necessarily other languages).
Personally I think you can have pointer arithmetic, or good code but never bother at the same time. There is zero reason to use pointer arithmetic, not performance and certainly not readability. If you doubt this then take a modern compiler, write the same piece of code twice but once using pointer arithmetic and the other using array notation. Then compile them to ASM and compare the output. If the outputs are different at all then get a better compiler and then use array notation. //edit - if of course you weren't looking for a comparison of array index notation to array pointer notation then ignore all this.// |
|
|||
|
Well you can't add or delete from an array (it has constant size) and a pointer is literally just an address that points to another entity (so search time is constant since a pointer only every points to one thing).
Search time for an array depends on the data. If it is sorted it can be done quickly via a binary search. Otherwise the worse case is linear performance for a linear search (i.e. search time is proportional to the length of the array on average). If you want fast add, delete and search you are better off with a hash table. //edit - naturally you will have to find a C implementation of a hash table first.// |
|
|||||
|
Generally, it will depend highly on what you're planning to do. If you're working in C++ then I would use a vector instead of an array, and save pointers for linking data together in things like nodes in linked lists.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic Arrays | Fedex | C and C++ | 3 | 12-02-2007 05:45 PM |
| Derived Classes Can't Set Function Pointers | dargueta | C and C++ | 11 | 11-05-2007 10:04 PM |
| Issue writing to file: pointer to a class which contains pointers to other classes | Sheemer | C and C++ | 0 | 08-21-2007 02:17 AM |
| Arrays | clookid | PHP Tutorials | 1 | 01-11-2007 09:30 PM |
| Arrays | Sionofdarkness | C and C++ | 5 | 07-26-2006 06:35 PM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |