What is Pointers: Definition and 90 Discussions

In computer science, a pointer is an object in many programming languages that stores a memory address. This can be that of another value located in computer memory, or in some cases, that of memory-mapped computer hardware. A pointer references a location in memory, and obtaining the value stored at that location is known as dereferencing the pointer. As an analogy, a page number in a book's index could be considered a pointer to the corresponding page; dereferencing such a pointer would be done by flipping to the page with the given page number and reading the text found on that page. The actual format and content of a pointer variable is dependent on the underlying computer architecture.
Using pointers significantly improves performance for repetitive operations, like traversing iterable data structures (e.g. strings, lookup tables, control tables and tree structures). In particular, it is often much cheaper in time and space to copy and dereference pointers than it is to copy and access the data to which the pointers point.
Pointers are also used to hold the addresses of entry points for called subroutines in procedural programming and for run-time linking to dynamic link libraries (DLLs). In object-oriented programming, pointers to functions are used for binding methods, often using virtual method tables.
A pointer is a simple, more concrete implementation of the more abstract reference data type. Several languages, especially low-level languages, support some type of pointer, although some have more restrictions on their use than others. While "pointer" has been used to refer to references in general, it more properly applies to data structures whose interface explicitly allows the pointer to be manipulated (arithmetically via pointer arithmetic) as a memory address, as opposed to a magic cookie or capability which does not allow such. Because pointers allow both protected and unprotected access to memory addresses, there are risks associated with using them, particularly in the latter case. Primitive pointers are often stored in a format similar to an integer; however, attempting to dereference or "look up" such a pointer whose value is not a valid memory address will cause a program to crash. To alleviate this potential problem, as a matter of type safety, pointers are considered a separate type parameterized by the type of data they point to, even if the underlying representation is an integer. Other measures may also be taken (such as validation & bounds checking), to verify that the pointer variable contains a value that is both a valid memory address and within the numerical range that the processor is capable of addressing.

View More On Wikipedia.org
  1. O

    How to Approach This Limit Involving a Riemann Sum?

    Hi all, perhaps someone can shed some light on the following sum: \lim_{m\rightarrow\infty}\frac{1}{m}\sum_{k=1}^{m-1}\left[1-\left(\frac{k}{2m-k}\right)^{1/2} \right]^2 What particularly throws me off is having the m variable as part of the summands. I have ran numerical simulations...
  2. O

    Pointers to start understanding topological insulators

    I've recently started learning about topological insulators. I've read a considerable amount of (review) papers on the subject, yet I still only have a phenomenological understanding of what a topological insulator is. I know for example, that the gapless surface states have to be there because...
  3. R

    C: Pointers, Strings & Compiler Warnings

    In C, why do you have to define a pointer type? For a 32 bit computer, the address is 4 bytes long no matter what, so it shouldn't matter if the pointer is to a char or an int, yet I get a compiler warning when I use a char pointer to point to the address of an int. Also, I don't quite...
  4. E

    How Does a Pointer Behave Like an Array in C Programming?

    So I'm learning C, and I think I'm doing pretty well so far. Anyway, I'm up to Arrays, and some code that was posted in the tutorial is this: #include <stdlib.h> int main() { int* myArray = malloc( sizeof(int) * 20 ); // could write int myArray[20]; instead. myArray[5] =...
  5. M

    Rewriting a function using pointers

    I have an original code that searches through "s" for a specific character then stores this into a pointer (otherwise, null). This is the original code: const char* findMe(const char s[], char c) { for (int k = 0; s[k] != 0; k++) if (s[k] == c) return...
  6. Simfish

    Are pointers important for scientific research?

    A lot of scientific programs are CPU-intensive, so speed is important. Pointers have to do with memory management, which I presume is important since there are often so many array values that memory management becomes important. yet, I don't see it used very often. Are they used very often?
  7. A

    Pointers and multidimensional arrays in C

    /* Demonstrates passing a pointer to a multidimensional */ /* array to a function. */ #include <stdio.h> void printarray_1(int (*ptr)[4]); void printarray_2(int (*ptr)[4], int n); main() { int multi[3][4] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }...
  8. A

    Adding Arrays Together with Pointers in C

    #include <stdio.h> #define K 10 int array1[K], array2[K]; int *ptr; int addarrays(int x[],int y[]); main() { int count; for (count = 0;count < K; count++) { puts("Enter numbers into array1"); scanf("%d", array1[count]); }...
  9. W

    Need some pointers on some puzzling questions

    Hey all, I'm taking a physics class dealing with harmonic motion and wave motion, and the last homework assignment of the quarter was given a bit late (i.e. after we began to cover extraneous lectures that are abstract and challenging), so I'm finding it hard to get back into the swing of...
  10. D

    Cannot compare pointers to strings?

    After compiling the code below, GCC says that you can't compare a pointer to string by iso C++ standards. But I don't see a pointer anywhere (I don't know pointers for now...did it long ago, now forgot)...may be it has to do with the fact that arrays are called by reference. char...
  11. J

    Pointers, Ram, Hard drives and Databases

    A long time ago, I was once told that too much reliance on databases in programing can create slow programs. Databases provide a nice way to store and organize information but they may not retrieve and write information quickly. Clearly ram is the fastest way to access meomry but the size of ram...
  12. T

    IB Extended Essay in Physics, focusing on Fibre optics, any pointers?

    I am not entirely sure where to post this, please tell me if anything needs to be changed This is my first post so i'll introduce myself... My name is Joe, currently aged 17 and in year 13 in school in Kent, Uk doing the International Baccalaureate (Not sure how well known this is? Quite...
  13. Artlav

    Strong laser pointers - facts?

    Recently, i obtained a 100mW green laser pointer, and the thing gets me confused. On one side, the beam is bright enough to see from some distance at 90* angle to it, and the point is visible on a hillside some miles away. On the other hand, it doesn't burn anything, like advertisements often...
  14. D

    What is the feasibility of using laser pointers to paint the moon?

    I ran across this site from 2001: http://www.afineline.org/projects/paint.html Apparently it didn't work very well. Anybody care to guess what kind of equipment it would take to make a red splotch appear on the moon to the naked eye from earth?
  15. L

    C++ Pointers & Classes: Translating $0-9999

    Hi I am new using pointers and i am having a hard time trying to figure out how to write a program in c++ using pointers and classes. The program can be used to translate whole dollar amounts in the range 0 through 9999 into an English description of the number. For example, the number 713...
  16. Z

    Pointers not allowed to used iostream

    I want to infinitely print a saying to the console but I am not allowed to used iostream. I am using the function putc. I understand I need to use an infinite loop. So far I have: int main() { char *word; word = &SAYING[0]; while(true) { putc(*word, stdout); word ++...
  17. W

    C/C++ Question about pointers in C/C++

    Isn't a pointer simply a memory address? Then why is the following illegal? int x = 1; char *p = &x; &x should simply evaluate to an address in memory and that should be stored in the content of p. If this was run on a 32-bit architecture, under ASCII formatting, then *p = 'a'; Will modify...
  18. T

    Is it Correct to Replace '\0' with a Website Address in a Char Array?

    in this code i got a chat type pointer which is an array who consists out of 4 char cells in order that each pointer cell of this array will point to some place we need to give it an address some thing like &chr "Monday morning" is not an address and its not a single char this...
  19. T

    C/C++ Need help soon with C++ program using pointers and arrays

    Okay so I got the majority of my program complete, however when I try to run it it doesn't display the proper value of the average. I think I somehow messed up using my pointers and arrays, but I can't locate the problem and I've spent hours trying to fix it to no avail. see comments for better...
  20. L

    Can you explain the size difference between arrays and pointers in C?

    int* a1 = malloc(4 * sizeof(int)); int* a2 = malloc(3 * sizeof(int)); int* a3 = malloc(5 * sizeof(int)); a1[0] = 1; a1[1] = 2; a1[2] = 3; a1[3] = 4; a2[0] = 9; a2[1] = 8; a2[3] = 7; a3[0] = -1; a3[1] = -2; a3[2] = -3; a3[3] = -4; a3[4] = -5; My question: Are a1, a2 and a3 arrays? I...
  21. W

    C/C++ [C++] Pointers to member functions

    Hi, I was hoping a C++ guru could help me with a problem I'm having using the gnu science library (gsl) in my C++ code. Here is my issue: Take for instance the Runge Kutter codes for solving differential equations. You need to supply the gsl routines for this a pointer to a function describing...
  22. R

    C Pointers: Guide to Understanding & Using | Boredzo.org

    Looks like useful link: http://boredzo.org/pointers/
  23. rohanprabhu

    Problem with array of pointers

    Mentor note: Long-time member who hasn't been around for a couple years. This is a problem worth investigating, though, IMO. There was a problem in an assignment I was solving, which asked me to break up the elements of a linked list into 3 different linked lists. Rather than creating 3 linked...
  24. R

    How to Implement a Dynamic Circular Chasing Pointer Array of Integers?

    Circular chasing pointers... Can anyone please point me towards a site that can explain how to implement a dynamic circular chasing pointer array of integers? Thanks in advance
  25. A

    How to Assign Inputs as Addresses in C Programming?

    Hi guys, ***I just started c programming, I've done some reading last week and i came up with a basic program.Ive got a problem trying to assign an input as an adress to a specified value.Basically i have 3 datas in my array and it will be called by inputting a number which points to the...
  26. B

    Doing a presentation. Need some pointers.

    Hi I'm currently starting to prepare a 15 min preparation on a chemistry topic. The topic I have been chosen to do is ''New methods of functionalizing armonatic rings; New methods for the constructing of C-O bonds to functionalize aromatic rings'' Does anyone have some pointers to...
  27. rohanprabhu

    Problems with Linked List and pointers

    I've tried to implement a list within a class. I did this so that I can make 2 or more objects, where each object has a list as it's member. Here is the code to it: struct coeffecient { int num; int den; }; struct polynomial { float power; coeffecient coeff; int...
  28. P

    Homework help or pointers anyone?

    homework help or pointers anyone? A 1.29-cm-tall object is placed 31.1 cm to the left of a converging lens with a focal length f1 = 20.4 cm. A diverging lens, with a focal length f2 = -42.4 cm, is placed 31.1 cm to the right of the first lens. How tall is the final image of the object? im...
  29. MathematicalPhysicist

    What is the difference between ++p and p++ in C pointers?

    if i have declared int *p and afterwards, in the progress of the programme iv'e typed ++p or p++ is there any difference between and what exactly is the difference? thanks advance.
  30. P

    Comp Sci Trouble Expanding an Array of pointers in C++

    Homework Statement I am working on a program that reads in names (strings), sorts them, and then later is searchable. The problem I am having is this. When I enter the first 20 elements of the array, everything works fine. When I enter the 21 element (when it goes into the if loop) I get...
  31. W

    Motion detection pointers?

    there seem to be no forum for applied math on PF, but can anyone here point me to simplest yet efficient yet not covered by evil patents algorithm for motion detection between two/more consecutive images?
  32. P

    Solving Pointer in C Language: Placing ptr on name1,2,3

    pointers ...C language I need your help: name1 < name 2 > name 3 I m writing a problem that place: a pointer on name 1 a pointer on name 2 a pointer on name 3 I have been working on it more than 24 hours but in vain :cry: what i did is strcmp with < if it is place ptr 1 (it...
  33. M

    Circular motion - pointers of a clock

    (a) What's the time between 9h and 10h in which the minute and hour pointers are equal? (b) After midday, what's the first time in which the three pointers are equal? For (a), I tried to do: \Theta = \Theta_0 + \omega_{hours} \cdot t \omega = \frac{2 \cdot \pi}{T} \Theta_0 = 270^o...
  34. S

    Comp Sci C++ Pointers: Get Help Understanding Basics & Memory Savings

    Can anyone help me understand the basic use of pointers. I am aware of pointers,yet I feel that a program can be made more easier without using a pointer. My basic dout is that can pointers be used to save memory by dynamic declaration of variables. I thought over it but found that using...
  35. D

    Help with My Pointer Problem in Function - Input Skipping

    In my program have a function like this: void * changeInfo(bool *flag, string *NewName) { if (!(*flag)) { cout << endl << "Enter the new Name: "; getline(cin, *NewName); cout << *NewName; } } My problem is reading the input using the pointer to a...
  36. Oxymoron

    Need Help with Inner Product Space X Questions?

    I am working through some exercises and need some help on a couple of questions. 1. Show that in any inner product space X that B[x;r] = x+rB[X] := \{x+ry\,:\, y\in B[X]\} where B[X] is the closed unit ball. 2. Show that the closed unit ball is convex. I have thought about these...
  37. Math Is Hard

    How can I declare an array of pointers to arrays of characters in C?

    I am not sure I wrote this correctly, but I am trying to declare an array of 12 pointers to arrays of 50 characters: char *names[12] [50] Does this look OK? Thanks.
  38. Math Is Hard

    Passing pointers and arrays to a C function

    This is the latest assignment I am struggling with: Write a program that contains a function void shift(char *) that looks at the first character of its argument and converts the other characters, to be the same case, that is, if the first character is uppercase, it shifts the rest to...
  39. Math Is Hard

    C programming: working with pointers

    I have run into a little bit of confusion working with pointers and I am trying to figure out which of the expressions below from my assignment are valid. My definition of a pointer is that it is a variable that contains a memory address, so I get confused about whether I am modifying a location...
  40. P

    Java Java Pointers and Missing method body

    I declare my pointer as char* ptr and my function as public boolean FuncFoo() but java compiler complains that I have some problem with identifier right at * and my function is missing the method body... I couldn't figure out what was wrong with them. Would you please help me ? Thank you,
Back
Top