๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_pointers.php
C Pointers
In the example above, we used the pointer variable to get the memory address of a variable (used together with the & reference operator). You can also get the value of the variable the pointer points to, by using the * operator (the dereference operator):
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ c-pointers
Pointers in C - GeeksforGeeks
The data type indicates the type of variable the pointer can point to. For example, "int *ptr;" declares a pointer to an integer.
Published ย  3 weeks ago
Discussions

Pointer Variables in C - Stack Overflow
so I just had a quick question, I thought originally that code in general executes from top to bottom. So below I have attached an example in C using pointers and would just like someone to explain... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How do function pointers in C work? - Stack Overflow
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 ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Dereferencing a char Pointer in C
Initializing a pointer creates space for the pointer itself but not for the resulting value... So char* p doesn't actually create the 1 byte needed for a char anywhere in memory. You have to do that explicitly in C. Add a malloc statement for example. https://www.gnu.org/software/libc/manual/html_node/Basic-Allocation.html Also if you malloc don't forget to free! Welcome to C, where the memory manager is you, dear coder :) #include #include int main(void) { char *p = (char*) malloc(sizeof(char)*1); *p = 'p'; printf("%c\n", *p); free(p); return 0; } Does this make sense? More on reddit.com
๐ŸŒ r/CodingHelp
3
3
April 30, 2021
pointers in C
Here's a book: https://www.amazon.com/Understanding-Pointers-C-Yashavant-Kanetkar/dp/8176563587 int x = 5; int *p = &x; printf("%p\n", p); printf("%d", *p); A pointer (at least in C) is a variable that stores a memory address. I'll repeat this again: pointers are VARIABLES. However, instead of storing some kind of integer or float value, pointers hold memory addresses. On the first line above, I've defined a variable 'x' and assigned it to the value 5. Here, we're storing 5 in a memory block, let's call this block "x", which will hold two things: 1) the value 5 and 2) the address of the block. The address of the block just tells us where the value is stored on your computer, just like your home address tells a person where you may live in your town. In programming, your computer (more accurately, your computer memory) is the town. A pointer is more akin to an address book, but a "book" that has a single page with only one address. A pointer comes with two operators: 1) the address operator (the ampersand &) and the deference operator (the pound symbol *). The address operator gives you the address of where a particular value is stored in memory while the dereference operator gives you the actual value. The * symbol is also used to declare that a specific variable is a pointer in C. Going through the short snippet of code above, in line 2, I'm declaring a pointer with the variable name 'p' and then assigning it to the memory address of x (hence why I use &). On the third line, I'm printing the pointer (which stores the memory address) and that will ultimately display an address (in hexadecimal in the terminal). On the last line, instead of printing the address/pointer, I dereferenced the pointer to get the value stored at the specified address using the * operator. Here's another analogy I'll end off on: Let's say I have a class of 5 people and I've scattered random objects across the room. I give each person a sticky note that describes where they can find an object in the room. In this scenario, the sticky notes would be the pointers that hold the address of an object in the room. More on reddit.com
๐ŸŒ r/C_Programming
22
12
August 18, 2022
๐ŸŒ
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
๐ŸŒ
w3resource
w3resource.com โ€บ c-programming-exercises โ€บ pointer โ€บ index.php
C programming exercises: Pointer - w3resource
October 16, 2025 - Pointer : Demonstrate the use of & and * operator : -------------------------------------------------------- m = 300 fx = 300.600006 cht = z Using & operator : ----------------------- address of m = 0x7ffda2eeeec8 address of fx = 0x7ffda2eeeecc ...
๐ŸŒ
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
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_pointers_arrays.php
C Pointers and Arrays
Well, in C, the name of an array, is actually a pointer to the first element of the array. Confused? Let's try to understand this better, and use our "memory address example" above again.
๐ŸŒ
Dremendo
dremendo.com โ€บ c-programming-tutorial โ€บ c-pointer
Pointer in C Programming | Dremendo
The & operator is used to store the address of variable a in pointer variable *x using the statement x=&a. So we can say that the variable x points to the value of the variable a by storing its address. Note: The above memory addresses are imaginary address used for explaining the pointer. The actual address varies from computer to computer. To access the value of a variable using a pointer, use the * operator with the pointer variable. See the examples ...
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ c-pointer-functions
C Pass Addresses and Pointers to Functions
Inside the function, we increased the value stored at ptr by 1 using (*ptr)++;. Since ptr and p pointers both have the same address, *p inside main() is also 11. ... Your builder path starts here. Builders don't just know how to code, they create solutions that matter.
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ cprogramming โ€บ c_pointers.htm
Pointers in C
The value of the variable which is pointed by a pointer can be accessed and manipulated by using the pointer variable. You need to use the asterisk (*) sign with the pointer variable to access and manipulate the variable's value. In the below example, we are taking an integer variable with ...
๐ŸŒ
Yale University
cs.yale.edu โ€บ homes โ€บ aspnes โ€บ pinewiki โ€บ C(2f)Pointers.html
C/Pointers
Because array names act like pointers, they can be passed into functions that expect pointers as their arguments. For example, here is a function that computes the sum of all the values in an array a of size n:
๐ŸŒ
TechVidvan
techvidvan.com โ€บ tutorials โ€บ pointers-in-c-language
Pointers in C with Examples - TechVidvan
July 17, 2021 - In C, we can use an array of pointers to make your coding simple and easy. ... In the above example, we have declared point as an array of 4 integer pointers.
Top answer
1 of 5
7

Let's break it down:

int a = 10, *p1, *p2;  // nothing special
p1 = &a;               // p1 now holds the address of a. printf("%d", *p1) would print 10, as it is the current value of a.

// in this point, printf("%d-%d", *p1,a); would print 10-10 (printf("%d",*p2); is UB as p2 is uninitialized)

*p1 = 25;              // remember that p1 = &a, meaning that now a = 25. Basically you changed (the variable) a, using a pointer instead of changing it directly.
p2 = p1;               // p2 now holds the value of p1, meaning it too points to a

// in this point, printf("%d-%d-%d", *p1,*p2,a); would print 25-25-25

*p2 = 12;              // *p2 = 12, and so does *p1, and so does a

// in this point, printf("%d-%d-%d", *p1,*p2,a); would print 12-12-12

 printf("%d", *p1);

You should remember that a is an int that holds an integer value, and p1,p2 are int * that hold the address of an int. After p1 = &a, every change to a would mean that *p1 is changed too, since *p1 is actually *(&a) [which is...a]. After p2 = p1, the same holds for p2.


I thought originally that code in general executes from top to bottom.

Well, it does :)

2 of 5
5

Address values used here is totally arbitrary, just for example

int a = 10, *p1, *p2;

the previous line declare one variable of type int (a) and two pointers to int (p1 and p2)

memory after the previous line

address | memory | variable
1050    | 10     | a
1054    | xxx    | p1
1058    | xxx    | p2

p1 = &a; // &a is address of a, ie here, 1050

memory after the previous line

address | memory | variable
1050    | 10     | a
1054    | 1050   | p1 
1058    | xxx    | p2
  • p1 stores "1050"; *p1, ie value stored at address stored inside p1, is 10

*p1 = 25; // *p1 means value stored at address stored inside p1

memory after the previous line

address | memory | variable
1050    | 25     | a
1054    | 1050   | p1 
1058    | xxx    | p2
  • p1 stores "1050"; *p1, ie value stored at address stored inside p1, is now 25

p2 = p1;

memory after the previous line

address | memory | variable
1050    | 25     | a
1054    | 1050   | p1 
1058    | 1050   | p2
  • p1 stores "1050"; *p1, ie value stored at address stored inside p1, is 25
  • copy values stored inside p1 in p2; so p2 points to a, ie stores address "1050"

*p2 = 12;

memory after the previous line

address | memory | variable
1050    | 12     | a
1054    | 1050   | p1  
1058    | 1050   | p2

printf("%d", *p1); // Print value stored at address stored inside p1

What we can see here:

  • p1 and p2 are pointers: they store address of variable
  • & (like in &a): returns address of a variable
  • * in declaration (like in int *p1): declare pointer to a variable (here to a int variable)
  • * in expression (like in *p1 = 25): access to value stored at address stored in pointer

You can see different addresses and values :

printf("address of a: %p\n", &a);
printf("address of p1: %p\n", &p1);
printf("address of p2: %p\n", &p2);

// address stored inside p1 (ie value stored inside p1)
printf("address stored inside p1: %p\n", p1);
// address stored inside p2 (ie value stored inside p2)
printf("address stored inside p2: %p\n", p2);

printf("value of a: %d\n", a);
printf("value pointed by p1: %d\n", *p1);
printf("value pointed by p2: %d\n", *p2);
Top answer
1 of 12
1807

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
357

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?
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ pointers-in-c-programming
How to Use Pointers in C Programming
May 3, 2023 - A pointer can also point to another pointer variable. This is known as a "pointer to a pointer". We declare a pointer to a pointer by using two asterisks **. For example: ... Here, q is a pointer to a pointer. It points to the address of the p variable, which in turn points to the address of the x variable
๐ŸŒ
Scaler
scaler.com โ€บ topics โ€บ c โ€บ pointer-declaration-in-c
Pointer Declaration in C - Scaler Topics
July 11, 2024 - In the example above, we have done a pointer declaration and named ptr1 with the data type integer. ... 22 ways of initializing a pointer in C once the pointer declaration is done.
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ c-programming โ€บ pointers
Pointers in C Language (Uses, Types, Examples)
August 29, 2025 - Learn about pointers in C, their types, and uses with examples. Understand pointer basics, operations, and memory management in C programming.
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Pointer_(computer_programming)
Pointer (computer programming) - Wikipedia
4 days ago - Another common use of pointers is to point to dynamically allocated memory from malloc which returns a consecutive block of memory of no less than the requested size that can be used as an array. While most operators on arrays and pointers are equivalent, the result of the sizeof operator differs. In this example, sizeof(a) will evaluate to 5 * sizeof(int) (the size of the array), while sizeof(ptr) will evaluate to sizeof(int *), the size of the pointer itself.
๐ŸŒ
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, function pointers etc.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ cprogramming โ€บ c_pointer_to_pointer.htm
Pointer to Pointer (Double Pointer) in C
When we define a "pointer to a ... that contains the actual value as shown below โˆ’ ยท The declaration of a pointer to pointer (double pointer) is similar to the declaration of a pointer, the only difference is that you need to use an additional asterisk (*) before the pointer variable name. For example, the following declaration declares a "pointer to a pointer" of type int...
๐ŸŒ
Study.com
study.com โ€บ courses โ€บ computer science courses โ€บ computer science 111: programming in c
Pointers in C Programming: Definition, Examples & Use - Lesson | Study.com
February 4, 2024 - The linked representation of data structures including linked lists, stacks, graphs, queues, and trees are created using pointers in C programming. 6. System-level programming that includes memory addresses ยท The best example for this application could be shared memory implementation using multiple threads.