Software and Applications (non-game)
C Programming
C++ Programming
The Difference Between

Difference between pointers and arrays in C?

353637

Top Answer
User Avatar
Wiki User
Answered
2008-10-01 19:48:12
2008-10-01 19:48:12

They're related but not totally comparable.

A pointer is an address in memory where a variable is located.

An array is a conceptual data representation consisting of a list of more than one item of a particular scalar type (int, float, char, structure, etc.) where each element is accessed by its index. The index can be thought of as a counter or enumerator telling you how many elements you have to skip over to get to the one you're interested in. Here's where addresses come in ... the location of a particular element in memory is offset from the so-called base address (i.e. the address of the starting element) by the value

(sizeof(one element) * index #)

The C compiler is smart enough to take the sizeof() into account when you do pointer arithmetic, so you can find the address of the i-th element as (address of base) + i, rather than having to do the multiplication explicitly.

The idea of element address as offset also accounts for C's use of zero-relative array definitions. Since the first element is offset by 0 positions from the first element its index in C is 0, not 1. The second (ordinal) element is offset from the first by 1 position so its index is 1, and so on.

345
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0

Related Questions


There is a difference: a pointer is a number that literally points to a place in memory. Arrays are groupings of a type. There is a close relationship between pointers and arrays, however: every expression with arrays (example: array[i]) can be expressed with pointers (example: *(array + i)), because for the computer, an array is just a list of pointers to the type of the array.

Some of them are: 1. char, short, int, long, float, double 2. pointers to these 3. arrays of these 4. arrays of pointers 5. pointers to arrays ...

Java doesn't have pointers. C++ has pointers.

Arrays are implemented as pointers in c.

arrays are the reserved sets of variables, which are supposed to store the similar data. pointers are the special variables which store the address of other variables.

Nothing whatsoever. They are exactly the same.

A pointer is simply a variable that can store a memory address and has the same purpose in both languages. The only real difference is that C++ pointers can point at objects (instances of a class) and indirectly invoke their methods, whereas pointers in C (which is not object oriented) cannot.

You can define pointers to every data-type (including elementary types, structures, unions, arrays and function), plus you can define generic pointers as 'void *'.

In computer terminology, pointer is a programming language. It is an important part of C language. Uses of pointers: C pointer, C arrays, C linked list, memory-mapped hardware, Pass-by-address using pointers, Dynamic memory allocation.

Yes. All string variables are pointers as are other arrays.

That would include header files, data types, loops, functions, pointers, arrays

Java is an object-oriented language, without pointers, garbage collected. C is a procedural language, with pointers, not garbage collected. Basically, the standard distribution of Java compiles to C and then to machine code.

Structures and arrays are somewhat similar in that they both "contain" multiple items of data in one package. Arrays contain several copies of the same type of data one after another. An array's elements must all be "char", "int", "float", pointers of a single type, structs or any other type. Structures, on the other hand, contain multiple variables, each with a specific data type. Structures can also contain arrays. The actual, literal differences between structures and arrays involve understanding addresses and pointers, which may come in handy later on during your foray into more advanced concepts in C.

An array is a collection of objects of similar data type ,whereas pointers are variable which is used to hold the address of the other variable.

C plus supports the use of pointers, where as java does not. because the use of pointers may makes the coding difficult. C plus supports multiple inheritance. where as java does not supports multiple inheritance. java is platform independent.

Because of pointers and that all arrays are really pointers. A pointer something like *pointer can also be written as pointer[0] and *(pointer + 1) can also be written as pointer[1]

Arrays, pointers, structures and unions are all derived types in C. These types build upon the built-in types and can be used recursively to derive new types.

1.Dynamic memory allocation is possible with pointers. 2.passing arrays and structures to functions 3.passing addresses to functions. 4.creating data structures such as trees,linked lists etc

There are no array operations in C. Arrays implicitly convert to pointers, thus any operation you might attempt upon an array you would actually perform on a pointer.

There is no difference. A string is just an array of type char. The only real difference is that we do not need to keep track of the length of a string because strings are null-terminated in C. If a string does not have a null-terminator, then it is just an ordinary array of character values.

You can't. While a string is a character array, an array is not necessarily a string. Treating arrays as if they were strings simply to swap them is madness. The correct way to physically swap arrays A and B is to copy A to a new array, C, then copy B to A, then C to B. If the arrays are the same size this is not a problem. If they are different sizes, you can only swap them if they are dynamic (not static). This means you must reallocate them. To speed up the process, copy the smallest array to C, first. A much better approach would be to point at the two arrays and swap the pointers instead.

a pointer is a derived data type in c. pointers are undoubtedly one of the most distinct and exciting features of c language.it has added power and flexibility to the language. *pointers are more efficient in handling arrays and tables. *pointer can be used to support dynamic memory management. *pointers reduce length and complexity of programs. *increase the execution speed and thus reduce the program execution time. by following character's real power of c lies in proper use of pointers. pointer is called the jewel of c-language.

NULL is a constant with the value zero. It is typically used with pointers to signify the pointer is valid, but it does not store a valid memory address. In other words it points at nothing in particular. It is nullified. All pointers that are not currently in use must be nullified to signify the fact they are not in use. The term empty applies to arrays that have no elements: empty arrays. We also use the term when referring to empty strings. A string is simply an array of char, but while null-terminated strings always have at least one char, the null-terminator, the string itself is empty.

It is not possible to declare a two-dimensional array using an array of pointers in any programming language, but many programming languages support declarations of N-dimensional arrays of pointers.The exact syntax varies with the programming language, and requires support for N-dimensional arrays and pointers. In C, the following declares an array of pointer variables, each implemented as pointer to the generic type "void":void* array_1D[10];The type of the expression array_1D is "void * const."The following example expands on the previous one by declaring a two-dimensional array of "void" pointers:void* array_2D[10][20];The type of the expression array_2D is "void ** const."The last example declares a 3-dimensional array of "void" pointers, which can be seen as a 2-dimensional array of arrays of pointers:void* array_3D[10][20][30];

Turbo C is an earlier C compiler from Borland. ANSI C is the standard for the C programming language. Therefore, the two are different by definition - Turbo C is a computer program, and ANSI C is a specification for a computer program, which can be implemented in various ways. If we rephrase the question as "what are the difference between the C versions as depicted in the ANSI standard and as implemented in Turbo C?" I would say that most are PC-specific such as the use of far pointers.


Copyright ยฉ 2020 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.