🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-pointers
Pointers in C - GeeksforGeeks
Always initialize pointers with a valid address or NULL before using them to avoid errors. ... A dangling pointer is a pointer that refers to a memory location that has already been deallocated or freed. Accessing such a pointer leads to undefined behavior. Dereferencing a dangling pointer can cause program crashes, incorrect results, or memory access errors.
Published: 2 weeks ago
🌐
W3Schools
w3schools.com › c › c_pointers.php
C Pointers
A C pointer stores the memory address of another variable.
Discussions

Why Use Pointers in C? - Stack Overflow
I'm still wondering why in C you can't simply set something to be another thing using plain variables. A variable itself is a pointer to data, is it not? So why make pointers point to the data in... More on stackoverflow.com
🌐 stackoverflow.com
How do function pointers in C work? - Stack Overflow
I must add a disclaimer that I ... programming style in C, so there probably are points that I didn't explain well, or may just be off mark in terms of how best to implement OOP in C. But my purpose was to try to illustrate one of many uses of function pointers... More on stackoverflow.com
🌐 stackoverflow.com
Genuine question: What’s hard about pointers?
Try using them for implementing a simple bubble sort algorithm, Then try doing the same without pointers. You'll know the difference. More on reddit.com
🌐 r/learnprogramming
38
28
February 14, 2022
Why pointers?
Lets say you would like to make a grid based game, for this you would need an array of tiles of course. You would want to get a tile at x, y without looping trough the entire array to find the right tile. So you would wanna say "Hey give me the tile at x and y". This could be done in either of 2 ways. translating the x and y to a single integer. For example (x + y * width) this would give a single integer that can be passed on the array as normal. Or you would fill the array with pointers that point to another array. This makes an 2D array. Each x points to the array containing the y. Now you could just call the array as shown here (array[x][y]). Another reason for pointers is because in C an struct's size ALWAYS has to be known before compiling. This is because the memory management system has to reserver the bytes needed by the struct. So if you would want an array inside the struct but you don't know the size of the array before the program starts, (for example you ask the user how many elements need to be created). this means the array needs to be stored outside of the struct. So we create a pointer inside the struct (a pointer is always 4 bytes on a x32 system) that points to the array. Now we can just get the pointer adress with a malloc(elements * sizeof(elementinarray)). And voilah we have a dynamic size array (not really, we need to create a new array every time we want to increase of decrease the size). Side note: EVERY and EVERY malloc has to have corresponding free() call More on reddit.com
🌐 r/C_Programming
42
34
October 20, 2017
🌐
Reddit
reddit.com › r/c_programming › best pointers explanation
r/C_Programming on Reddit: Best Pointers Explanation
December 15, 2023 -

Could anyone recommend a video that provides a clear explanation of pointers in C programming? I've been struggling to understand them, and I'm looking for a resource that breaks down the concept effectively.

Code style: Pointers Jun 24, 2025
r/C_Programming
last yr.
pointers in C Aug 18, 2022
r/C_Programming
4y ago
Tips/Guides on pointers Dec 10, 2023
r/C_Programming
2y ago
Arrays and Pointers as a beginner Oct 30, 2024
r/C_Programming
last yr.
More results from reddit.com
🌐
Medium
lorenzopiombini.medium.com › pointers-in-c-2ad210278a51
Pointers in C. a Beginner guide. | by Lorenzo Piombini | Medium
September 13, 2024 - Program result. this value 0x16fcf3860 is the memory address of the variable numb2, the value itself will be different on your machine, obviously, but you can see pointers in action in this simple example, remember, a pointer is a variable that holds another variable memory address.
🌐
Cornell Virtual Workshop
cvw.cac.cornell.edu › cintro › advanced-types › pointers
Cornell Virtual Workshop > Introduction to C Programming > Advanced Data Types > Pointers
Line 02 initializes a variable named q and sets it's value to 5. Line 03 uses the & to assign p the "address of variable q". Line 04 sets the "value of the integer pointed to by p" to 10, and since p is pointing to q's memory, q now has the value of 10. This is just an example of what pointers can do. The usefulness of pointers is that they allow the programmer to alter a variable in a function, as well as assist the programmer in achieving optimal speeds, clarity and simplicity.
🌐
Programiz
programiz.com › c-programming › c-pointers
C Pointers (With Examples)
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. For example: int* pc, c; c = 5; pc = &c; printf("%d", *pc); // Output: 5
🌐
Yale University
cs.yale.edu › homes › aspnes › pinewiki › C(2f)Pointers.html
C/Pointers
Memory in a typical modern computer is divided into two classes: a small number of registers, which live on the CPU chip and perform specialized functions like keeping track of the location of the next machine code instruction to execute or the current stack frame, and main memory, which (mostly) lives outside the CPU chip and which stores the code and data of a running program. When the CPU wants to fetch a value from a particular location in main memory, it must supply an address: a 32-bit or 64-bit unsigned integer on typical current architectures, referring to one of up to 232 or 264 distinct 8-bit locations in the memory. These integers can be manipulated like any other integer; in C, they appear as pointers, a family of types that can be passed as arguments, stored in variables, returned from functions, etc.
Find elsewhere
🌐
Medium
michaeladev.medium.com › pointers-in-c-a-beginners-guide-9c54ae6e59bb
Pointers in C: A Beginner’s guide | by Michael Appiah Dankwah | Medium
February 1, 2023 - Pointers are a fundamental concept in C programming that allow you to manipulate data stored in memory. Understanding pointers is essential for efficient memory management and is a crucial part of C programming.
🌐
freeCodeCamp
freecodecamp.org › news › pointers-in-c-programming
How to Use Pointers in C Programming
May 3, 2023 - Next, we used dynamic memory allocation to allocate an array of three integers. We set the values of the array elements using pointer arithmetic (arr[0] = 1, arr[1] = 2, etc.). We then declared a pointer q that points to the first element of the array. Furthermore, we used pointer arithmetic to access and print the values of each element of the array. Finally, we freed the memory that was allocated to the array using the free function. This program demonstrates how pointers can be used to modify the value of a variable, access elements of an array using pointer arithmetic, and dynamically allocate and free memory.
🌐
Wikipedia
en.wikipedia.org › wiki › Pointer_(computer_programming)
Pointer (computer programming) - Wikipedia
1 month ago - I do consider assignment statements and pointer variables to be among computer science's "most valuable treasures." — Donald Knuth, Structured Programming, with go to Statements · In computer science, a pointer is an object in many programming languages that stores a memory address.
🌐
Amazon
amazon.com › Pointers-Programming-Management-Recursive-Structures › dp › 1484269268
Pointers in C Programming: A Modern Approach to Memory Management, Recursive Data Structures, Strings, and Arrays: Mailund, Thomas: 9781484269268: Amazon.com: Books
Pointers in C Programming: A Modern Approach to Memory Management, Recursive Data Structures, Strings, and Arrays [Mailund, Thomas] on Amazon.com. *FREE* shipping on qualifying offers. Pointers in C Programming: A Modern Approach to Memory Management, Recursive Data Structures, Strings, and Arrays
Top answer
1 of 4
42

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.

🌐
Wikibooks
en.wikibooks.org › wiki › C_Programming › Pointers_and_arrays
C programming/Pointers and arrays - Wikibooks, open books for an open world
June 9, 2004 - How to reference the value to which the pointer points (known as dereferencing, by using the dereferencing operator '*': value = *pointer;) How they relate to arrays (the vast majority of arrays in C are simple lists, also called "1 dimensional arrays", but we will briefly cover multi-dimensional arrays with some pointers in a later chapter).
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_pointers.htm
Pointers in C
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.
🌐
Steve's Data Tips and Tricks
spsanderson.com › steveondata › posts › 2025-03-05
The Complete Guide to C Pointers: Understanding Memory and Dereferencing – Steve’s Data Tips and Tricks
March 5, 2025 - Discover the fundamentals of pointers in C programming, including memory addresses, pointer variables, and dereferencing. This comprehensive guide is designed for beginners, providing clear explanations and practical examples to help you master pointers and enhance your coding skills.
🌐
w3resource
w3resource.com › c-programming-exercises › pointer › index.php
C programming exercises: Pointer - w3resource
Pointer : Show the basic declaration of pointer : ------------------------------------------------------- Here is m=10, n and o are two integer variable and *z is an integer z stores the address of m = 0x7ffd40630d44 *z stores the value of m = 10 &m is the address of m = 0x7ffd40630d44 &n stores the address of n = 0x7ffd40630d48 &o stores the address of o = 0x7ffd40630d4c &z stores the address of z = 0x7ffd40630d50 ... Write a program in C to demonstrate how to handle pointers in a program.
Top answer
1 of 12
1829

Function pointers in C

Let's start with a basic function which we will be pointing to:

int addInt(int n, int m) {
    return n+m;
}

First thing, let's define a pointer to a function which receives 2 ints and returns an int:

int (*functionPtr)(int,int);

Now we can safely point to our function:

functionPtr = &addInt;

Now that we have a pointer to the function, let's use it:

int sum = (*functionPtr)(2, 3); // sum == 5

Passing the pointer to another function is basically the same:

int add2to3(int (*functionPtr)(int, int)) {
    return (*functionPtr)(2, 3);
}

We can use function pointers in return values as well (try to keep up, it gets messy):

// this is a function called functionFactory which receives parameter n
// and returns a pointer to another function which receives two ints
// and it returns another int
int (*functionFactory(int n))(int, int) {
    printf("Got parameter %d", n);
    int (*functionPtr)(int,int) = &addInt;
    return functionPtr;
}

But it's much nicer to use a typedef:

typedef int (*myFuncDef)(int, int);
// note that the typedef name is indeed myFuncDef

myFuncDef functionFactory(int n) {
    printf("Got parameter %d", n);
    myFuncDef functionPtr = &addInt;
    return functionPtr;
}
2 of 12
361

Function pointers in C can be used to perform object-oriented programming in C.

For example, the following lines is written in C:

String s1 = newString();
s1->set(s1, "hello");

Yes, the -> and the lack of a new operator is a dead give away, but it sure seems to imply that we're setting the text of some String class to be "hello".

By using function pointers, it is possible to emulate methods in C.

How is this accomplished?

The String class is actually a struct with a bunch of function pointers which act as a way to simulate methods. The following is a partial declaration of the String class:

typedef struct String_Struct* String;

struct String_Struct
{
    char* (*get)(const void* self);
    void (*set)(const void* self, char* value);
    int (*length)(const void* self);
};

char* getString(const void* self);
void setString(const void* self, char* value);
int lengthString(const void* self);

String newString();

As can be seen, the methods of the String class are actually function pointers to the declared function. In preparing the instance of the String, the newString function is called in order to set up the function pointers to their respective functions:

String newString()
{
    String self = (String)malloc(sizeof(struct String_Struct));

    self->get = &getString;
    self->set = &setString;
    self->length = &lengthString;

    self->set(self, "");

    return self;
}

For example, the getString function that is called by invoking the get method is defined as the following:

char* getString(const void* self_obj)
{
    return ((String)self_obj)->internal->value;
}

One thing that can be noticed is that there is no concept of an instance of an object and having methods that are actually a part of an object, so a "self object" must be passed in on each invocation. (And the internal is just a hidden struct which was omitted from the code listing earlier -- it is a way of performing information hiding, but that is not relevant to function pointers.)

So, rather than being able to do s1->set("hello");, one must pass in the object to perform the action on s1->set(s1, "hello").

With that minor explanation having to pass in a reference to yourself out of the way, we'll move to the next part, which is inheritance in C.

Let's say we want to make a subclass of String, say an ImmutableString. In order to make the string immutable, the set method will not be accessible, while maintaining access to get and length, and force the "constructor" to accept a char*:

typedef struct ImmutableString_Struct* ImmutableString;

struct ImmutableString_Struct
{
    String base;

    char* (*get)(const void* self);
    int (*length)(const void* self);
};

ImmutableString newImmutableString(const char* value);

Basically, for all subclasses, the available methods are once again function pointers. This time, the declaration for the set method is not present, therefore, it cannot be called in a ImmutableString.

As for the implementation of the ImmutableString, the only relevant code is the "constructor" function, the newImmutableString:

ImmutableString newImmutableString(const char* value)
{
    ImmutableString self = (ImmutableString)malloc(sizeof(struct ImmutableString_Struct));

    self->base = newString();

    self->get = self->base->get;
    self->length = self->base->length;

    self->base->set(self->base, (char*)value);

    return self;
}

In instantiating the ImmutableString, the function pointers to the get and length methods actually refer to the String.get and String.length method, by going through the base variable which is an internally stored String object.

The use of a function pointer can achieve inheritance of a method from a superclass.

We can further continue to polymorphism in C.

If for example we wanted to change the behavior of the length method to return 0 all the time in the ImmutableString class for some reason, all that would have to be done is to:

  1. Add a function that is going to serve as the overriding length method.
  2. Go to the "constructor" and set the function pointer to the overriding length method.

Adding an overriding length method in ImmutableString may be performed by adding an lengthOverrideMethod:

int lengthOverrideMethod(const void* self)
{
    return 0;
}

Then, the function pointer for the length method in the constructor is hooked up to the lengthOverrideMethod:

ImmutableString newImmutableString(const char* value)
{
    ImmutableString self = (ImmutableString)malloc(sizeof(struct ImmutableString_Struct));

    self->base = newString();

    self->get = self->base->get;
    self->length = &lengthOverrideMethod;

    self->base->set(self->base, (char*)value);

    return self;
}

Now, rather than having an identical behavior for the length method in ImmutableString class as the String class, now the length method will refer to the behavior defined in the lengthOverrideMethod function.

I must add a disclaimer that I am still learning how to write with an object-oriented programming style in C, so there probably are points that I didn't explain well, or may just be off mark in terms of how best to implement OOP in C. But my purpose was to try to illustrate one of many uses of function pointers.

For more information on how to perform object-oriented programming in C, please refer to the following questions:

  • Object-Orientation in C?
  • Can you write object oriented code in C?
🌐
Codeforwin
codeforwin.org › home › pointer programming exercises and solutions in c
Pointer programming exercises and solutions in C - Codeforwin
July 20, 2025 - Pointer is a variable that stores memory address. In this pointer exercise I will cover most of the pointer related topics from a beginner level. Practice these examples to learn concepts like pointer basics, arithmetic, pointer to pointers, ...
🌐
WsCube Tech
wscubetech.com › resources › c-programming › pointers
Pointers in C Language (Uses, Types, Examples)
July 27, 2026 - Learn in this tutorial about pointers in C with types and examples. Understand their basics, operations, and uses for better memory handling in C programming.
🌐
Medium
medium.com › @Dev_Frank › pointers-in-c-422cccdbf2f6
POINTERS IN C. Pointer is a variable that stores the… | by Dev Frank | Medium
February 16, 2024 - Pointers are variable that stores the memory address of another variable. Instead of holding the actual value, it holds the location (address) of where the value is stored in the computer’s memory.