๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_structs_pointers.php
C Structs and Pointers
Use pointers with C structs to pass and modify structured data efficiently.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ structure-pointer-in-c
Structure Pointer in C - GeeksforGeeks
C language provides an array operator (->) that can be used to directly access the structure member without using two separate operators. Below is the program to access the structure members using the structure pointer with the help of the Arrow ...
Published: December 23, 2024
Discussions

(C) Understanding pointers and data structures, need help!
Hey, a few weeks ago i was introduced to pointers and basic datastructures primarily linked lists and Hash tables. So far as iโ€™ve understood itโ€™s used more for efficiency compared to normal arrays. More on reddit.com
๐ŸŒ r/learnprogramming
19
28
December 22, 2022
When should I declare struct instances as pointers and when shouldn't i?
C has the interesting property that it sort of treats structs like...well, what's called a 'primitive' type in Java for example. Suppose you have int a = 2 and then say int b = a, you have made b which holds a complete copy of a's value. Naturally. So, supposing you have struct Foo { int x[999999]; };. Then we say struct Foo a;. If you examine sizeof(a) you'd see that it's a chonker. If we go on to say struct Foo b = a;, then we have created a b which holds an entire separate copy of a's value. sizeof(a) == sizeof(b). Just as if they were ints. This is, frankly, weird. You see how carelessly using this feature could slurp up a ton of memory in a hurry. This plays heavily in function calls. C is call-by-value, so when you pass a struct to a function, you are creating a whole copy of that struct to send as the argument. You might want that, rarely, but often you do not. What you can do instead is send the address of the struct, a pointer, which is a uniformly tiny object. In Java, we'd say it's a reference. So, we can declare a function void baz(struct Foo* c);, and call it by saying baz(&a);. The pointer c that baz sees is a word-sized pointer to the struct a, no matter how big a actually is. sizeof(c) == sizeof(struct Foo*) == sizeof(int*). Significantly, this also lets baz modify the original a. If you don't want that, and also don't want to be passing around entire struct bodies, you use the const qualifier (which doesn't make it a constant, it just makes the compiler nag you if you forget to treat it as one). This explanation probably raises more questions than it answers. More on reddit.com
๐ŸŒ r/C_Programming
8
2
November 19, 2022
What is the difference between structs and pointer to structs?
The struct is the actual location in memory that holds the values of all the variables. The struct* just contains the memory address of the beginning of that location. When you do book->author; it's the same as (*book).author; Edit: Forgot my semicolons More on reddit.com
๐ŸŒ r/C_Programming
13
4
August 21, 2021
Question son generic structures and void pointers

In addition to the void* method, there's this trick I'd describe as "slightly abusive". Basically you have a "base struct" that just has a next in it. And then you include that struct in your data struct as the first field. Then you can cast your data struct to the base struct to get to the next.

(AFAIK, there's no UB or IB here, but someone please let me know if I'm mistaken.)

#include <stdio.h>
#include <stdlib.h>

// Generic linked list stuff up here

struct node {
struct node *next;
};

struct llist {
struct node *head;
};

void llist_for_each(struct llist *l, void (*f)(void *))
{
for (struct node *p = l->head; p != NULL; p = p->next)
f(p);
}

void llist_init(struct llist *l)
{
l->head = NULL;
}

// In this function, n must point to a struct node or a struct that has
// struct node as the first member:

void llist_insert(struct llist *l, void *n)
{
struct node *new_node = n;
struct node *old_head;

old_head = l->head;
new_node->next = old_head;
l->head = new_node;
}

// Custom stuff below here

struct custom_node {
struct node llist_data; // Must be first!

int a;
char b;
float c;
};

struct custom_node *new_custom_node(int a, char b, float c)
{
struct custom_node *n = malloc(sizeof *n);

n->a = a;
n->b = b;
n->c = c;

return n;
}

void print_custom_node(void *node)
{
struct custom_node *n = node;

printf("%d %c %f\n", n->a, n->b, n->c);
}

int main(void)
{
struct llist l;

llist_init(&l);

llist_insert(&l, new_custom_node(1, 'a', 1.1));
llist_insert(&l, new_custom_node(2, 'b', 2.2));
llist_insert(&l, new_custom_node(3, 'c', 3.3));

llist_for_each(&l, print_custom_node);
}

// Output:
//
// 3 c 3.300000
// 2 b 2.200000
// 1 a 1.100000
More on reddit.com
๐ŸŒ r/C_Programming
11
2
September 15, 2021
๐ŸŒ
Reddit
reddit.com โ€บ r/cprogramming โ€บ struggling to understand structure pointers
r/cprogramming on Reddit: Struggling to understand Structure Pointers
December 29, 2023 -

I am a newbie to C. I recently learned about pointers and am comfortable with int pointers. However, I am having a hard time with structures.For instance, if I give a pointer to a structure how does the pointer point to all the data stored in the struct? How would that even be possible?Let me give an example -

int digit = 5
int *ptr = &digit; // Let's assume &digit is 1001 
// Therefore ptr is now 1001

However, a structure is a contigous block of memory. What would a pointer to it store?

Top answer
1 of 5
14
struct is a continuous block of memory, with the fields inside the struct with a fixed layout. Therefore, if you know the address of the struct, and you have the struct definition, you also know the addresses of all the fields in the struct. If you know the address of an integer (for example). You know the address of an integer. It doesn't matter if the integer is inside of a struct, in an array, nor does it matter if it is in stack, or allocated with malloc or a global variable. If you have a valid address of a valid integer, you have an address of an integer. Also, memory addresses are at byte accuracy. Not all members of a struct have the same address, in fact they all have a different address, and only the first member has same address as the whole struct (but different pointer type).
2 of 5
9
#include #include // Simple example struct struct s { int a; int b; }; int main() { // Instantiate a struct. struct s s1 = {1, 2}; // Get a pointer to the struct. struct s *s_ptr = &s1; // Print the value of the pointer, which is the address of s1. printf("address: %p\n", s_ptr); // Access s1's member `a` through the pointer with the arrow operator. printf("member a: %d\n", s_ptr->a); // Access s1's member `b` through the pointer with a dereference and a dot. // The parentheses are necessary because the dot operator has precedence // over the dereference. printf("member b: %d\n", (*s_ptr).b); return 0; } Example output: address: 0x7ffcd540fc30 member a: 1 member b: 2
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ pointers with structures in c
Pointers and Structures in C - Scaler Topics
June 10, 2022 - C allows programmers to create ... any other data type in C, variables of user-defined structure occupy addresses in a memory block, and pointers can be used to point them....
๐ŸŒ
Swarthmore College
cs.swarthmore.edu โ€บ ~newhall โ€บ cs31 โ€บ resources โ€บ C-structs_pointers.php
CS31: Intro to C Structs and Pointers
(note: technically, everything in C is passed by value; C-style pass-by-reference is just passing the value of an address (a pointer) to a function as opposed to passing the value of an int or float or ...) Dynamic Memory Allocation A common uses of pointer variables is to use them to point to memory that your program allocates at runtime. This is very useful for writing programs where the size of an array or other data structure is not know until runtime, or that may grow or shrink over the lifetime of a run of a program. malloc and free are functions for allocating and deallocating memory in the Heap.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ cprogramming โ€บ c_pointers_to_structures.htm
Pointers to Structures in C
However, you can avoid it by creating a shorthand notation using the typedef keyword. Pointers to structures are very important because you can use them to create complex and dynamic data structures such as linked lists, trees, graphs, etc.
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ c-structures-pointers
C structs and Pointers (With Examples)
Enter the number of persons: 2 Enter first name and age respectively: Harry 24 Enter first name and age respectively: Gary 32 Displaying Information: Name: Harry Age: 24 Name: Gary Age: 32 ยท In the above example, n number of struct variables are created where n is entered by the user. To allocate the memory for n number of struct person, we used, ptr = (struct person*) malloc(n * sizeof(struct person)); Then, we used the ptr pointer to access elements of person.
๐ŸŒ
CodeChef
codechef.com โ€บ blogs โ€บ pointers-in-c
Pointers and Structures in C (Examples and Practice)
Pointers are a fundamental concept in C programming that allow you to directly manipulate memory by storing the memory addresses of variables and data structures.
Find elsewhere
๐ŸŒ
Weber State University
icarus.cs.weber.edu โ€บ ~dab โ€บ cs1410 โ€บ textbook โ€บ 5.Structures โ€บ pointers.html
5.4. Structures And Pointers
Programs frequently use pointers in conjunction with structures. Consequently, programmers use all pointer and memory allocation operators with them. However, the arrow operator is the most frequent because it selects individual fields within a structure, allowing programs to save and retrieve ...
๐ŸŒ
BimStudies
bimstudies.com โ€บ home โ€บ docs โ€บ pointers โ€บ c programming
Pointers and Structures โ€“ BimStudies.Com
June 1, 2025 - struct StructureName { data_type member1; data_type member2; // ... other members }; struct StructureName *ptr; // pointer to a structure ... #include <stdio.h> struct Point { int x; int y; }; int main() { struct Point p1 = {10, 20}; struct Point *ptr; ptr = &p1; // pointer points to structure p1 // Access structure members using pointer printf("x = %d, y = %d\n", ptr->x, ptr->y); // Modify members using pointer ptr->x = 30; ptr->y = 40; printf("Modified x = %d, Modified y = %d\n", p1.x, p1.y); return 0; }
๐ŸŒ
Dyclassroom
dyclassroom.com โ€บ c โ€บ c-pointers-and-structures
C - Pointers and Structures - C Programming - dyclassroom | Have fun learning :-)
So, to create a pointer for the student structure we will write the following code. ... We use the following syntax to assign a structure variable address to a pointer. ... In the following example we are assigning the address of the structure variable std to the structure pointer variable ptr.
๐ŸŒ
DEV Community
dev.to โ€บ mikkel250 โ€บ structures-and-pointers-in-c-n6i
Structures and pointers in C - DEV Community
December 26, 2019 - Because the above uses integers (with a known, fixed size), dynamic memory allocation is not necessary. If strings were used, then memory allocation would be used, because structures do not allocate space to store strings. Both of the below are valid ways to declare structures, and while there are advantages to using pointers, it is important to understand how they work with structures. struct names { char firstName[20]; char lastName[20]; } // or struct pnames { char *first; char *last; }
๐ŸŒ
Study.com
study.com โ€บ computer science courses โ€บ computer science 111: programming in c
Using Pointers with Structures in C Programming: Overview & Examples - Lesson | Study.com
December 13, 2023 - Now that we have a struct (video game) and have reviewed the creation of pointers, let's look at how pointers and structs can work together. To unlock this lesson you must be a Study.com member Create an account ยท Let's think about our game struct. Because we don't have the luxury of object-oriented programming in C, we have used a struct. But now we want to take it a step further: We want to create a type of abstract data type, which is a structure that hides its implementation from the outside world.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ pointer to structure in c
Pointer to Structure in C - Scaler Topics
June 20, 2022 - Similarly, we can have a Pointer to Structures, In which the pointer variable point to the address of the user-defined data types i.e. Structures. Structure in C is a user-defined data type which is used to store heterogeneous data in a contiguous manner. Before Declaration of Pointer to ...
๐ŸŒ
HowStuffWorks
computer.howstuffworks.com โ€บ tech โ€บ computer software โ€บ programming
Pointers to Structures - The Basics of C Programming | HowStuffWorks
March 8, 2023 - Using the array of pointers allows the array to take up minimal space until the actual records are allocated with malloc statements. The code below simply allocates one record, places a value in it, and ...
๐ŸŒ
Sdds
intro2c.sdds.ca โ€บ pointers, arrays and structs
Pointers, Arrays and Structs | Introduction to C
We can model RAM as a linear map ... the address 1 identifies the second byte and address 512Mb-1 identifies the last byte. ... A pointer is a variable that stores an address....
๐ŸŒ
Medium
medium.com โ€บ @muirujackson โ€บ simple-explanation-of-structure-with-pointer-in-c-d12f0d4e4992
Simple explanation of structure with Pointer in C | by Muiru Jackson | Medium
March 21, 2023 - So the main difference between ... is that a structure variable stores the actual values of the members, while a structure pointer stores the memory address of a structure variable and allows us to access the members indirectly...
๐ŸŒ
Medium
medium.com โ€บ @itsvishalchavda โ€บ the-c-programming-pointer-to-structure-d6f439780b28
The C Programming โ€” Pointer to Structure: | by Vishal Chavda | Medium
March 4, 2025 - the only difference is that the C structure has members. So, we need to learn how to manipulate these members using pointer. And again, the syntax is simple like we access structure member using dot(.) notation, here with pointer we use the ...
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ structure pointer in c | create, uses & more (+code examples)
Structure Pointer In C | Declare, Initialize & Uses (+Examples)
July 26, 2024 - A structure pointer in C programming language is a pointer that points to a structure variable. It allows us to access and manipulate the data within the structure indirectly using the pointer.
๐ŸŒ
DEV Community
dev.to โ€บ its_srijan โ€บ pointers-in-c-structure-and-pointer-to-pointer-2kn9
Pointers In C - Structure and Pointer to Pointer - DEV Community
August 13, 2020 - But, it is one of the features which make C an excellent language. 0. Pointer to Structure 1. Array Of Structure 2. Pointer to Structure as an Argument 3. Pointer to Pointer ยท Like integer pointers, array pointers and function pointers, we have pointer to structures or structure pointers as well.