Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Pointer? [duplicate]

See: Understanding Pointers


In many C flavoured languages, and some older languages like Fortran, one can use Pointers.

As someone who has only really programmed in basic, javascript, and actionscript, can you explain to me what a Pointer is, and what it is most useful for?

Thanks!

like image 879
defmeta Avatar asked Sep 30 '08 16:09

defmeta


People also ask

What is a pointer in C++?

A pointer is a variable that stores the memory address of another variable as its value. A pointer variable points to a data type (like int) of the same type, and is created with the * operator. The address of the variable you're working with is assigned to the pointer:

What is the difference between a pointer and a variable?

In the example above, &myAge is also known as a pointer. A pointer is a variable that stores the memory address of another variable as its value. A pointer variable points to a data type (like int) of the same type, and is created with the * operator.

What is the use of pointers in Java?

Pointers provide an efficient way for accessing the elements of an array structure. Pointers are used for dynamic memory allocation as well as deallocation. Pointers are used to form complex data structures such as linked list, graph, tree, etc. Pointers are a little complex to understand.

What is a wild pointer?

A pointer is said to be a wild pointer if it is not being initialized to anything. These types of pointers are not efficient because they may point to some unknown memory location which may cause problems in our program and it may lead to crashing of the program.


1 Answers

This wikipedia article will give you detailed information on what a pointer is:

In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address. Obtaining or requesting the value to which a pointer refers is called dereferencing the pointer. A pointer is a simple implementation of the general reference data type (although it is quite different from the facility referred to as a reference in C++). Pointers to data improve performance for repetitive operations such as traversing string and tree structures, and pointers to functions are used for binding methods in Object-oriented programming and run-time linking to dynamic link libraries (DLLs).

like image 92
David Segonds Avatar answered Sep 23 '22 18:09

David Segonds