One common place where pointers are helpful is when you are writing functions. Functions take their arguments 'by value', which means that they get a copy of what is passed in and if a function assigns a new value to one of its arguments that will not affect the caller. This means that you couldn't write a "doubling" function like this:

void doubling(int x)
{
    x = x * 2;
}

This makes sense because otherwise what would the program do if you called doubling like this:

doubling(5);

Pointers provide a tool for solving this problem because they let you write functions that take the address of a variable, for example:

void doubling2(int *x)
{
    (*x) = (*x) * 2; 
}

The function above takes the address of an integer as its argument. The one line in the function body dereferences that address twice: on the left-hand side of the equal sign we are storing into that address and on the right-hand side we are getting the integer value from that address and then multiply it by 2. The end result is that the value found at that address is now doubled.

As an aside, when we want to call this new function we can't pass in a literal value (e.g. doubling2(5)) as it won't compile because we are not properly giving the function an address. One way to give it an address would look like this:

int a = 5;
doubling2(&a);

The end result of this would be that our variable a would contain 10.

Answer from tuckermi on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-pointers
Pointers in C - GeeksforGeeks
A pointer is initialized by assigning it the address of a variable using the address operator (&). ... Initializing a pointer ensures it points to a valid memory location before use. You can also initialize a pointer to NULL if it doesn’t point to any variable yet: int *ptr = NULL;
Published   November 14, 2025
🌐
W3Schools
w3schools.com › c › c_pointers.php
C Pointers
Create a pointer variable with the name ptr, that points to an int variable (myAge). Note that the type of the pointer has to match the type of the variable you're working with (int in our example). Use the & operator to store the memory address of the myAge variable, and assign it to the pointer.
People also ask

What are the types of pointers in C?
There are various types of pointers. Here are a few more: · Null Pointer · Void Pointer · Wild Pointer · Near pointer · Complex pointer · Huge pointer · Far pointer · Dangling pointer
🌐
byjus.com
byjus.com › gate › pointers-in-c
Pointers in C
What is the void pointer in C?
The void pointer is also known as the generic pointer in the C language. This pointer has no standard data type, and we create it with the use of the keyword void. The void pointer is generally used for the storage of any variable’s address.
🌐
byjus.com
byjus.com › gate › pointers-in-c
Pointers in C
Top answer
1 of 4
41

One common place where pointers are helpful is when you are writing functions. Functions take their arguments 'by value', which means that they get a copy of what is passed in and if a function assigns a new value to one of its arguments that will not affect the caller. This means that you couldn't write a "doubling" function like this:

void doubling(int x)
{
    x = x * 2;
}

This makes sense because otherwise what would the program do if you called doubling like this:

doubling(5);

Pointers provide a tool for solving this problem because they let you write functions that take the address of a variable, for example:

void doubling2(int *x)
{
    (*x) = (*x) * 2; 
}

The function above takes the address of an integer as its argument. The one line in the function body dereferences that address twice: on the left-hand side of the equal sign we are storing into that address and on the right-hand side we are getting the integer value from that address and then multiply it by 2. The end result is that the value found at that address is now doubled.

As an aside, when we want to call this new function we can't pass in a literal value (e.g. doubling2(5)) as it won't compile because we are not properly giving the function an address. One way to give it an address would look like this:

int a = 5;
doubling2(&a);

The end result of this would be that our variable a would contain 10.

2 of 4
20

A variable itself is a pointer to data

No, it is not. A variable represents an object, an lvalue. The concept of lvalue is fundamentally different from the concept of a pointer. You seem to be mixing the two.

In C it is not possible to "rebind" an lvalue to make it "point" to a different location in memory. The binding between lvalues and their memory locations is determined and fixed at compile time. It is not always 100% specific (e.g. absolute location of a local variable is not known at compile time), but it is sufficiently specific to make it non-user-adjustable at run time.

The whole idea of a pointer is that its value is generally determined at run time and can be made to point to different memory locations at run time.

🌐
Programiz
programiz.com › c-programming › c-pointers
C Pointers (With Examples)
You can also declare pointers in these ways. ... Let's take another example of declaring pointers. ... Here, we have declared a pointer p1 and a normal variable p2. Let's take an example. ... Here, 5 is assigned to the c variable. And, the address of c is assigned to the pc pointer. To get the value of the thing pointed by the pointers, we use the * operator.
🌐
TutorialsPoint
tutorialspoint.com › home › cprogramming › c pointers overview
Understanding C Pointers
June 10, 2012 - C pointer is the derived data type that is used to store the address of another variable and can also be used to access and manipulate the variable's data stored at that location.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › features-and-use-of-pointers-in-c-c
Features and Use of Pointers in C/C++ - GeeksforGeeks
July 28, 2025 - An array, of any type, can be accessed with the help of pointers, without considering its subscript range. Pointers are used for file handling. Pointers are used to allocate memory dynamically.
🌐
freeCodeCamp
freecodecamp.org › news › pointers-in-c-programming
How to Use Pointers in C Programming
May 3, 2023 - For example, to initialize the pointer p to point to an integer variable called x, we would write: ... This sets the value of p to be the memory address of x. Once we have a pointer that points to a specific memory location, we can access or modify the value stored at that location by dereferencing the pointer. To dereference a pointer, we use the asterisk * symbol again, but this time in front of the pointer variable itself.
Find elsewhere
🌐
Reddit
reddit.com › r/c_programming › why would anybody use pointers?
r/C_Programming on Reddit: Why would anybody use pointers?
May 16, 2022 -

Newbie here:
I know how pointers work, what do they do and how to deference them, but I don’t understand why would someone use pointers instead of the variable name. Can someone tell me what’s up?

Top answer
1 of 20
50
Every object in C is stored somewhere in its lifetime. As long as the object's lifetime lasts, it is guaranteed to: Exist Have a constant address Retain it's last-stored value There are times in your application, when you wish change an object's value but you want to do it outside its scope. This can mean passing a pointer to an object to a function, where the function will change the value of the original object. An example will be: void foo(int *a) { *a = 3; } void bar(int a) { a = 3; } int main(void) { int a = 2; bar(a); printf("%d\n", a); // Prints 2. foo(&a); printf("%d\n", a); // Prints 3. } bar doesn't change the value of a in main, because the a in bar is completely another object. In foo however, you are using the address of a which - while a lives - can only refer to the a in main. It is also worth noting a few things: Every object with the storage duration of allocated, can only be changed through pointers. Only automatic and static objects can have their values changed directly. u/TiagodePAlves talks about these. Their lifetime lasts from allocation (for example the library function malloc), to deallocation (for example the library function free) In all cases except when used as an operand of sizeof, the & operator or it is a string literal used to initialize an array, an array gets treated as a pointer to its first element! you probably used pointers implicitly already! EDIT: reddit formatting will never not make my life hell
2 of 20
24
You're probably looking at simple examples of pointers, which are not how you would typically use pointers in the real world. Here are a few examples of what you would use pointers for: Arrays where you don't know their size at compile time. Functions that need to return more than one variable. Variables or structs that need to be modified from the inside of a function call, similar to pass-by-reference in other languages. Anything that needs to have a different lifetime than the scope it was created in. Many third-party libraries will create structs or other "objects" internally and expose them by their address only, which you will then use within other function calls to that library. This type of pointer is usually called a handle.
🌐
BYJUS
byjus.com › gate › pointers-in-c
Pointers in C
August 1, 2022 - The pointers in C language refer to the variables that hold the addresses of different variables of similar data types. We use pointers to access the memory of the said variable and then manipulate their addresses in a program.
🌐
Scaler
scaler.com › topics › uses-of-pointers-in-c
What are the uses of pointers in c? | Scaler Topics
November 15, 2022 - The pointer size depends on the computer architecture, however, for a 32-bit system, the pointer used is 2 bytes. ... For passing the argument by using references. For accessing the elements of an array. For dynamic memory allocation by using malloc() and calloc() functions . Used in arrays, functions to improve the performance of code.
🌐
Wikipedia
en.wikipedia.org › wiki › Pointer_(computer_programming)
Pointer (computer programming) - Wikipedia
3 weeks ago - 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 ...
🌐
Quora
quora.com › When-should-we-use-a-pointer-in-C-program
When should we use a pointer in C program? - Quora
Any time you need to pass a data structure you need a pointer. You can pass simple data types (char, float, or int) but if you want to get a value back from a function more than just a return value, you need a pointer.
Top answer
1 of 16
233
  • Why use pointers over normal variables?

Short answer is: Don't. ;-) Pointers are to be used where you can't use anything else. It is either because the lack of appropriate functionality, missing data types or for pure perfomance. More below...

  • When and where should I use pointers?

Short answer here is: Where you cannot use anything else. In C you don't have any support for complex datatypes such as a string. There are also no way of passing a variable "by reference" to a function. That's where you have to use pointers. Also you can have them to point at virtually anything, linked lists, members of structs and so on. But let's not go into that here.

  • How do you use pointers with arrays?

With little effort and much confusion. ;-) If we talk about simple data types such as int and char there is little difference between an array and a pointer. These declarations are very similar (but not the same - e.g., sizeof will return different values):

char* a = "Hello";
char a[] = "Hello";

You can reach any element in the array like this

printf("Second char is: %c", a[1]);

Index 1 since the array starts with element 0. :-)

Or you could equally do this

printf("Second char is: %c", *(a+1));

The pointer operator (the *) is needed since we are telling printf that we want to print a character. Without the *, the character representation of the memory address itself would be printed. Now we are using the character itself instead. If we had used %s instead of %c, we would have asked printf to print the content of the memory address pointed to by 'a' plus one (in this example above), and we wouldn't have had to put the * in front:

printf("Second char is: %s", (a+1)); /* WRONG */

But this would not have just printed the second character, but instead all characters in the next memory addresses, until a null character (\0) were found. And this is where things start to get dangerous. What if you accidentally try and print a variable of the type integer instead of a char pointer with the %s formatter?

char* a = "Hello";
int b = 120;
printf("Second char is: %s", b);

This would print whatever is found on memory address 120 and go on printing until a null character was found. It is wrong and illegal to perform this printf statement, but it would probably work anyway, since a pointer actually is of the type int in many environments. Imagine the problems you might cause if you were to use sprintf() instead and assign this way too long "char array" to another variable, that only got a certain limited space allocated. You would most likely end up writing over something else in the memory and cause your program to crash (if you are lucky).

Oh, and if you don't assign a string value to the char array / pointer when you declare it, you MUST allocate sufficient amount of memory to it before giving it a value. Using malloc, calloc or similar. This since you only declared one element in your array / one single memory address to point at. So here's a few examples:

char* x;
/* Allocate 6 bytes of memory for me and point x to the first of them. */
x = (char*) malloc(6);
x[0] = 'H';
x[1] = 'e';
x[2] = 'l';
x[3] = 'l';
x[4] = 'o';
x[5] = '\0';
printf("String \"%s\" at address: %d\n", x, x);
/* Delete the allocation (reservation) of the memory. */
/* The char pointer x is still pointing to this address in memory though! */
free(x);
/* Same as malloc but here the allocated space is filled with null characters!*/
x = (char *) calloc(6, sizeof(x));
x[0] = 'H';
x[1] = 'e';
x[2] = 'l';
x[3] = 'l';
x[4] = 'o';
x[5] = '\0';
printf("String \"%s\" at address: %d\n", x, x);
/* And delete the allocation again... */
free(x);
/* We can set the size at declaration time as well */
char xx[6];
xx[0] = 'H';
xx[1] = 'e';
xx[2] = 'l';
xx[3] = 'l';
xx[4] = 'o';
xx[5] = '\0';
printf("String \"%s\" at address: %d\n", xx, xx);

Do note that you can still use the variable x after you have performed a free() of the allocated memory, but you do not know what is in there. Also do notice that the two printf() might give you different addresses, since there is no guarantee that the second allocation of memory is performed in the same space as the first one.

2 of 16
64

One reason to use pointers is so that a variable or an object can be modified in a called function.

In C++ it is a better practice to use references than pointers. Though references are essentially pointers, C++ to some extent hides the fact and makes it seem as if you are passing by value. This makes it easy to change the way the calling function receives the value without having to modify the semantics of passing it.

Consider the following examples:

Using references:

public void doSomething()
{
    int i = 10;
    doSomethingElse(i);  // passes i by references since doSomethingElse() receives it
                         // by reference, but the syntax makes it appear as if i is passed
                         // by value
}

public void doSomethingElse(int& i)  // receives i as a reference
{
    cout << i << endl;
}

Using pointers:

public void doSomething()
{
    int i = 10;
    doSomethingElse(&i);
}

public void doSomethingElse(int* i)
{
    cout << *i << endl;
}
🌐
Reddit
reddit.com › r/c_programming › what is the use of pointers in c?
r/C_Programming on Reddit: What is the use of pointers in C?
April 10, 2024 - Data structures is a big one, not to mention pointers to functions, allowing you to pass them around, passing functions as arguments to functions (like if you have a function that uses a filter but you want to be able to provide a filter so you can use the same function for different things, like a sorting function), even returning functions from functions, kind of like how functions are treated like objects in JavaScript, but not quite, passing in a variable to a function that can be changed in the function (even if that is frowned upon in some paradigms), if you have a large struct, it’s b
🌐
Simplilearn
simplilearn.com › home › resources › software development › pointers in c: a one-stop solution for using c pointers
Pointers in C: A One-Stop Solution for Using C Pointers
June 23, 2025 - A pointer in C is a variable pointing to the address of another variable. Explore C Pointer's ✓ types ✓ advantages ✓ disadvantages, and more. Start learning!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Cburch
cburch.com › books › cptr
Pointers in C
The value copied into ip will be the address of x, and the value copied into jp will be the address of y (Figure 4(a)). The line “t = *ip;” will copy the value referenced by ip (that is, x) into t. The next line will copy the value referenced by jp (that is, y) into the memory referenced by ip (that is, x) (Figure 4(b)). And the final line will copy the value of t (the original value of x) into the memory referenced by jp (that is, y) (Figure 4(c)). So the values contained by x and y will be swapped. [This is the only way to write such a function in C, where all parameters are passed by value. Some languages have a feature where you can designate a parameter to be an implicit pointer — it's called call by reference as opposed to the call by value used by C.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › applications-of-pointers-in-c-cpp
Applications of Pointers in C - GeeksforGeeks
Pointers in C are variables that are used to store the memory address of another variable. Pointers allow us to efficiently manage the memory and hence optimize our program.
Published   July 11, 2025
🌐
TASKING
resources.tasking.com › p › how-use-pointers-c-avoiding-errors-and-increasing-efficiency
How to Use Pointers in C: Avoiding Errors and Increasing Efficiency | Blog | TASKING
Pointers allow us to call an array, or edit values in an array without copying it into the call stack. When you use a pointer to access an array or data inside of an array the function merely copies the value of the pointer into the call stack.
🌐
Codedamn
codedamn.com › news › c programming
How to use pointers as parameters to function in C?
March 10, 2024 - Pointers are particularly useful when you need to pass large structures or arrays to a function, or when you want a function to modify the value of a variable. To declare a pointer, you use the asterisk symbol (*) before the pointer’s name.
🌐
Yale University
cs.yale.edu › homes › aspnes › pinewiki › C(2f)Pointers.html
C/Pointers
To initialize a pointer variable, ... a pointer to an int */ 3 4 p = &n; /* p now points to n */ Pointer variables can be used in two ways: to get their value (a pointer), e.g....