What is Pointers: Definition and 89 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. fluidistic

    Questions about C++, pointers, OS and compiler memory allocation

    Sorry I don't have the codes right now. In C plus plus, when I declare an int, but don't assign any value to it, a space in memory is allocated for it. I can define a pointer and check its adress in hexadecimal, so far so good. I can run this program over and over and usually the int is...
  2. shivajikobardan

    Comp Sci What happens in memory during DMA using pointers?

    #include<stdio.h> #include<stdlib.h> int main() { int *p; p=(int *) malloc(4); if(p==NULL) { printf("Insufficient memory"); return; } printf("Enter a number\n"); scanf("%d",p); printf("Value of p=%d",*p); } 1) What happens in background when we...
  3. C

    AI Computation (self study analysis, pointers welcome)

    In this thread I attempt to find a closed form solution to the gradient descent problem for a single sigmoid neuron using basic calculus. If you would like to give pointers feel free, if you see me make a mistake please let me know! Thank you!
  4. C

    Comp Sci Creating 2D Arrays with Pointers in C | Efficient Memory Allocation

    #include <stdio.h> #include<stdlib.h> int** make(int**x,int y,int z); void read(int **x,int y,int z); int main() { int ** r; int a,b; scanf("%d %d",&a,&b); /*r=(int**)malloc(sizeof(int*)*a); for(int i=0;i<b;i++){ r[i]=(int*)malloc(sizeof(int**)); }*/...
  5. REEEEEEEE

    Need pointers on how to convert schematic to breadboard

    Hello. I am supposed tolearn how to assemble the following circuit into a breadboard/protoboard but My attempts have all failed So I want to ask yyou how would you assemble his into a breadboard assuming that V and A are multimeters set to the previous(V and A) . how can I get the gist on...
  6. evinda

    MHB Why do we use & before ptr->points?

    Hello! (Wave) I have a question... 🧐 https://dyclassroom.com/c/c-passing-structure-pointer-to-function At the Complete code stated at the site above, at this part: for (i = 0; i < 3; i++) { printf("Enter detail of student #%d\n", (i + 1)); printf("Enter ID: "); scanf("%s"...
  7. Y

    Simple Question: Pointers and Uninitialized Variables Explained

    Why this doesn't work? #include<iostream> using namespace std; int main() { int* p; *p = 1;//error said uninitialized variable p used. cout << *p << endl; return 0; } I know if I do this, it works: #include <iostream> using namespace std; int main () { int* p; int x...
  8. Mark44

    C/C++ C++ swap routines: pointers vs. references

    @sysprog posted this code for a nifty swap function that uses XOR in another thread in this section. This put me in mind of a couple of swap routines that I did awhile back: one with references and one with pointers. Unlike the example above, both routines do use a third memory location. Rather...
  9. Y

    Please help with a problem displaying a string using pointers

    Hi I wrote a program to copy an array of C-String into dynamic memory in the function using pointers. I think I did it right, but I cannot display without garbage at the end of the string. //10.9 function copy C-String using pointer #include <iostream> using namespace std; void strCopy(char**...
  10. pj96

    Help with Numerical Problem: Pointers Needed!

    I'm really stuck on this and have no solution only a numerical answer! Any pointers in the right direction would be really appreciated!
  11. D

    What is the output of this C program with int pointers?

    Homework Statement I am supposed to analyze the code and find it's output without running it. Some things were unclear so i did run it and i have some things that puzzle me. Homework Equations 3. The Attempt at a Solution [/B] #include <stdio.h> #include <stdlib.h> #include <string.h> enum e...
  12. drgibbles

    Processor and Memory data alignment with base pointers?

    Hello, working on a puzzle and I think this may be what I need to do to solve it. I have a long string of characters,752 total with the range 0-9 and a-f. I believe that the data needs to be aligned based off the processor and memory. The Cpu is at 2800MHz and the memory is 1024MB. Is there a...
  13. doktorwho

    Help with pointers and strings in C

    Homework Statement I have to create a program that dynamically allocates a string and uses up no extra space (The string takes up as much space as it needs to),checks if entered string is 'please stop this', if it is then the prgogram exits and if it isn't then it continues, it makes a copy of...
  14. M

    C/C++ Usefulness of Pointers in C++?

    Hey everyone, I'm currently going over a chapter on pointers for my 2nd programming course (no prior experience outside of class). I'm wondering what the usefulness of pointers is, other than if you need direct access to the memory location of a variable. The text essentially says it's good...
  15. N

    MHB Fixing Code to Print "Print": Nodes and Pointers Programming Error

    what is wrong with my programming D: won't print out the "Print" #include <iostream> #include <cstdlib> #include<string> using namespace std; class Node { public: Node(); Node* prev; string key; Node* next; }; Node::Node() { prev = 0; next = 0; return; }...
  16. R

    Exercise on adding elements to a list

    (mentor note: moved here from another forum hence no template) This is the code with also the explanation of the exercise. There is bit of italian, but everything is clear enough. I actually solved the exercise. /* Add an element of value n before each element of the list that satisfies the...
  17. levadny

    Dynamic Arrays (One, two, three dimensions)

    Dear Friends! My post about dinamic arrays. For example little bit code. // size int const X = 5; int const Y = 4; int const Z = 3; // one dimension array printf("\nOne dimension\n"); // array of pointers int * Arr; // create array Arr = new int [X]...
  18. Prof. 27

    Comp Sci Problem with C++ Information Structures, Pointers, Arrays

    Homework Statement So I'm getting an error when I try to compile my C++ code: Debug Error Abort() has been called I have commented the code reasonably well, but the idea of the program is to take a file, separate the contents in each line to a part of a structure containing: Product Lookup...
  19. SnakeDoc

    Pointers -->(makes integer from pointer without cast)

    Homework Statement I am to write a program that has its user enter 100 character or less and determine if the line is a palindrome or not. I must use pointers one that starts at the beginning and one at the end of the array that must work their way in until they meet.(I'm also having trouble...
  20. SnakeDoc

    C Programming: Arrays and pointers

    Homework Statement So I created two arrays one called departure_time and the other arrival_time and populate each array as follows. I've tried both putting 8 and defining N as 8 int departure_times[N]={480, 538, 679, 767, 840, 945, 1140, 1305}; int arrival_times[N]={616, 712, 811, 900, 968...
  21. ChrisVer

    Pointers to const in func parameters

    I am not sure that I understand the following: http://www.cplusplus.com/doc/tutorial/pointers/ Why would someone pass an input to a function that he/she doesn't want to modify? And suppose that I want to do that, for example a function that runs a loop over N events determined within the main...
  22. ChrisVer

    Question on pointers (ROOT TTree example)

    TTree* inputTree = (TTree*)source->Get( "<YourTreeName>" ); Could someone please explain me what the above statements mean? I don't understand what " (TTree*) " does (source is a TFile). Thanks.
  23. cpscdave

    [Python] Function pointers & array of objects

    Maybe I am going about this the wrong way. I'm trying to build a form to display & update information in a object. The objects are stored in an array since I'll have 1-N of them. What I've done now is created an array of dictonaries which hold the information about the form fields, it...
  24. I

    C/C++ C++ String Functions with Pointers

    Assign the first instance of The in movieTitle to movieResult. Sample program: #include <iostream> #include <cstring> using namespace std; int main() { char movieTitle[100] = "The Lion King"; char* movieResult = 0; <STUDENT CODE> cout << "Movie title contains The? "; if...
  25. I

    C/C++ C++ Pointers and the Flush function

    I need some help understanding some things. One, I understand WHAT pointers do but how are they useful and how/when are they necessary? Two, what is the purpose of the flush function? This is the definition that I've been given: "The << flush forces cout to flush any characters in its buffer to...
  26. G

    Implementing strcat without string.h in C

    Hi everyone. This is similar to my strcpy question previously. I tried to code but when I ran the code, a segmentation fault appears. I think this has something to do with my loop for the array but I have problems resolving it. May I have some help please? Thank you. My codes and the original...
  27. J

    Are green <5mW laser pointers legal to use in New York City?

    I've been searching for a while, but all I seem to find is information about how it's illegal to sell laser pointers to minors in New York City. That and I find some information on what else is illegal to do with a laser pointer in NYC (pointing at vehicles, officers, etc.). There's a lot of...
  28. B

    Interpreting C pointers, dereferencing and indirection

    I have been going through a book on embedded development. I have been followin the C programs in the book with about 95% success as C is not completely new to me. But I am new to pointers so I was hoping someone would kindly clear a few things for me. #define INPUT (*((volatile unsigned long...
  29. C

    C allocating array of pointers

    I need some help with this piece of code I wrote earlier, it is compiling correctly but when I try to use my tester program it crashes. I am trying to create an array of pointers to struct Nodes typedef struct Node *NodeP; struct Node { NodeP next; EmployeeP info; }...
  30. A

    Why Are Pointers Necessary in Programming?

    "Pointers are variables that store address of another variable" But I don't understand why such a thing was necessary. The only thing they are useful for is when we want to permanently change something passed to a function. Since a function in C creates a local copy it only changes the value...
  31. A

    C Programming: Dynamic allocation of 2D arrays using an array of pointers.

    Homework Statement Ok, I'm learning C programming and I'm trying to create a dynamic 2D array. This is the code that seems to work in creating a dyamic array. I found it in a book. //rows and cols are values entered by the user when the program runs. int **(matA) =...
  32. N

    Proofing Linear Algebra: Tips, Advice and Pointers

    I have done some "proofs" before in calculus. At this moment I am required to write proofs for linear algebra and I find them highly unintuitive and confusing -- I often don't know where to begin or what to do. Can you guys leave some pointers, tips, advice, etc. for how to prove things...
  33. O

    New to electrical engineering (begginer), need some pointers please :p

    Anyways, I will first start off by saying my name is Aaron Orszak and I live in Montreal, Quebec. Lately I've been really into things like computer programming (python and ruby mainly) but I sadly gave up on it because it just didnt fill the void. Right now I am really into electronics and want...
  34. Z

    [C] Stupid pointers what the heck is going on here

    Hi, I don't understand how this can be so difficult. So I have a [char ** ptr] pointer that stores a list of arguments. I'm able to PRINT each of them by doing printf("%s\n", ptr[i]) But how the heck do I is strcmp to see if a certain argument is there? Apparently I cannot just do [if...
  35. F

    Schools Pointers needed in getting into physics grad school

    I aspire to getting into a reputable US physics grad school. As I'm aware of so far (correct me if I'm wrong), there are 4 main things grad schools look at: (in no particular order) 1. Your GPA 2. Your research experience 3. Recommendation letters 4. Your physics GRE score Do any of...
  36. T

    Pascal's Triangle: Pointers and Dynamic Memory Allocation

    Here is the given problem. I have a question for part c and e. Calculate and print first 12 rows of the famous Pascal triangle, as shown below. Each number is the sum of the two numbers immediately above it. As our intent is to practice pointers, functions, loops, and dynamic memory...
  37. T

    Comp Sci C++ compare strings program using pointers

    Homework Statement Create a function called isEqual(). isEqual() takes two strings and determines if the strings are identical. isEqual (s1, s2) should be the same as s1 = = s2 #include "stdafx.h" #include <iostream> using namespace std; bool isEqual(int *s, int *st, int x); int...
  38. P

    C: 2D arrays with structs and pointers

    I wanted to make a variant on having a player just walking around a small 2d map. Instead of having 2 variables to store the current x and y values of the player position in a certain array, I want to make a 2d array that is filled with NULL pointers. Then the player would be represented as a...
  39. Y

    Simpel question in C (tcshell) about strings and pointers

    If I need to write a c program which get a string from the stdin and prints it after a certain manipulation, the program is called that way: echo "Hello, World. bla bla bla" | program <arg> How can I save the string in my program before working on it? Thanks in advance
  40. E

    Comp Sci Creating an Array of Pointers to Objects in C++ Without Using Virtual Functions

    Homework Statement suppose i have class A. now i have 2 derative classes: A_1, A_2. i would like to create a 4'th class: Array_Class. Array_Class will have 2 pointers array (one for each class - A_1, A_2). i want to be able to get an object pointer from class A_1 or A_2, and place it in...
  41. F

    How to properly use pointers and structs in C?

    Hello all, I am experiencing some odd output behavior from a program that I am working on: Header file #include <pthread.h> struct ringbuf_t { pthread_mutex_t mutex; pthread_cond_t cond_full; pthread_cond_t cond_empty; int bufsiz; int front; int back; char* buf...
  42. D

    Using pointers in a User Define Function

    Homework Statement There is a user defined function that looks like this: void DisplayMenu(char *item) My problem is that I have no clue on how I could include "*item" in my function, without changing the name or algorithm. The purpose of this function to to display the list of apps...
  43. A

    Comp Sci Fortran debugging help: faulty pointers?

    Hi, I tried compiling my program in Fortran using the following commands: nagfor -g90 -C=all -C=undefined -g -gline -nan -u -mtrace=all test09b.f90 cell_functions.o -o test09b I ended up getting this error message: [Allocated item 15285 (size 17) = Z'FFFFFFFFB744A790'] Runtime Error...
  44. T

    Green Laser Pointer Reflecting: Hot or Not?

    Hey guys, I'm wondering.. If I were to reflect a green laser pointer to the mirror, will the reflected laser be hot too? Or will I be heating the mirror?
  45. J

    C/C++ Queue made with pointers in C++, questions

    Can someone explain how the function queue::store(int i) (see attachment) works for a sequence of calls to it. Or give a reference to something or give a diagram, please. Doesn't each instant (i.e., each memory location) have its own head, tail and next pointers as well as as the data member...
  46. C

    Pointers for the solution of 2nd order DE with variable coefficient

    Hi, I am looking at the following 2nd order DE with variable coefficient: y''(x)-(1/x+7)y(x)=0 I would be grateful for any help in regard to methods which may be applied to such an equation. Many thanks in advance! C.
  47. J

    Scope problem when filling a vector of base class pointers.

    I'm trying to write a simple program to calculate the impedance of an AC circuit consisting of an arbitrary number of resistors, capacitors and inductors combined in series or parallel. First I ask the user to create the components they wish to use in the circuit, and this is where I hit the...
  48. J

    Research internship cv - any pointers?

    I've pretty much finished writing a CV which I intend to email to some prospective summer research placements at universities in London and possibly internationally. Some bits are nagging me though, for example: In the education section I've listed my previous year grades, and my expected...
  49. T

    Recommendations for Self-Study in Math and Physics for Engineering Students

    First of all, sorry for my bad english, it isn't my primary language. I'll try to describe the courses I have taken as best as I can, since the school system and courses names here might not be the same as everywhere else. I completed college-level Physics I, II and III courses. Physics 1 was...
  50. O

    Pointers for solving a 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...
Back
Top