๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_structs_pointers.php
C Structs and Pointers
C Allocate Memory C Access Memory C Reallocate Memory C Deallocate Memory C Structs and Memory C Memory Example ยท C Errors C Error Challenge C Debugging C NULL C Error Handling C Input Validation ยท C Date C Random Numbers C Macros C Organize Code C Storage Classes C Bitwise Operators C Fixed-width Integers ... C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Practice Problems C Compiler C Syllabus C Study Plan C Interview Q&A ... You can use pointers with structs to make your code more efficient, especially when passing structs to functions or changing their values.
๐ŸŒ
Swarthmore College
cs.swarthmore.edu โ€บ ~newhall โ€บ cs31 โ€บ resources โ€บ C-structs_pointers.php
CS31: Intro to C Structs and Pointers
struct student { char name[50]; int age; int year; float gpa; }; In your program, you can declare variables whose type is struct student or struct student * (a pointer to a struct student). To access individual fields in a struct, use dot "." notation if the variable's type is "struct student" ...
Discussions

Struggling to understand Structure Pointers
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). More on reddit.com
๐ŸŒ r/cprogramming
17
21
December 29, 2023
How can I declare a Pointer to a struct in C? - Stack Overflow
If T is some type specifier then a pointer to an object of the type T can be declared in any of the following ways ... struct Card*p = &my_card; struct Card* p = &my_card; struct Card *p = &my_card; struct Card * p = &my_card; ... Also there exists another subtlety. If you will write for example More on stackoverflow.com
๐ŸŒ stackoverflow.com
why use pointer to struct and not use the struct directly (C) - Stack Overflow
I had a typo there in my example, in printf, I corrected it. 2020-05-04T20:18:43.133Z+00:00 ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Domain expertise still wanted: the latest trends in AI-assisted knowledge for... ... Iโ€™m Jody, the Chief Product and Technology Officer at Stack Overflow. Letโ€™s... 0 Is it bad practice to instantiate C struct object as global variable? 4 When is it worth using a pointer ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is there a reason to use a pointer to a struct instead of a struct, and what situations would one be preferred over the other??
Simple example: you have a very large struct you want to pass to a function. If you pass by value the struct, you will end up making a full copy of it, which will be a small performance hit since you'll likely spill your register file. If you pass by reference, you only have to pass a pointer (size depends on system), and you are less likely to spill. Two more differences from this. When you pass by value, modifications to the struct made in the callee won't be visible to the caller unless you have something like my_str = my_fn(my_str); However, in pass by reference, any modifications in the callee are observed in the caller as well More on reddit.com
๐ŸŒ r/C_Programming
21
13
May 9, 2018
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ c-structures-pointers
C structs and Pointers (With Examples)
#include <stdio.h> #include <stdlib.h> struct person { int age; float weight; char name[30]; }; int main() { struct person *ptr; int i, n; printf("Enter the number of persons: "); scanf("%d", &n); // allocating memory for n numbers of struct person ptr = (struct person*) malloc(n * sizeof(struct ...
๐ŸŒ
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 operator.
Published ย  December 23, 2024
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ cprogramming โ€บ c_pointers_to_structures.htm
Pointers to Structures in C
This is how you will define a new derived data type using the "struct" keyword โˆ’ ยท struct type { type var1; type var2; type var3; ... ... }; You can then declare a variable of this derived data type as following โˆ’
๐ŸŒ
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 - Also, the structure pointer can be initialized during the time of declaration. There are two ways to access the values of structure members using pointers - 1. Using asterisk (*) and dot (.) operator with the structure pointer. 2. Using membership or arrow (->) operator. Let us see some examples to understand how we can access structure members using two different approaches.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ structure-pointer-in-c
Structure Pointer in C - javatpoint
Structure Pointer in C with Tutorial, C language with programming examples for beginners and professionals covering concepts, c pointers, c structures, c union, c strings etc.
Find elsewhere
๐ŸŒ
OverIQ
overiq.com โ€บ c-programming-101 โ€บ pointer-to-a-structure-in-c
Pointer to a Structure in C - C Programming Tutorial - OverIQ.com
For example: (*ptr_dog).name - refers to the name of dog (*ptr_dog).breed - refers to the breed of dog ... Parentheses around *ptr_dog are necessary because the precedence of dot(.) operator is greater than that of indirection (*) operator. The above method of accessing members of the structure ...
๐ŸŒ
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 - Access the value through the pointer member using the arrow operator (->). Print the value to verify. Don't forget to free the dynamically allocated memory when you're done. Let's look at a code example to understand these steps. ... #include #include #include // Define the structure struct Person { char *name; // Pointer to a string int age; }; int main() { // Declare and initialize the structure struct Person p; // Allocate memory for the name p.name = malloc(50 * sizeof(char)); // Allocate space for 50 characters // Check if memory allocation was successful if (p.name == NULL) { fprintf(stderr, "Memory allocation failed\n"); return 1; } // Initialize the structure members strcpy(p.name, "Alia"); p.age = 30; // Access and print the structure members printf("Name: %s\n", p.name); printf("Age: %d\n", p.age); // Free the allocated memory free(p.name); return 0; }
๐ŸŒ
HowStuffWorks
computer.howstuffworks.com โ€บ tech โ€บ computer software โ€บ programming
Pointers to Structures - The Basics of C Programming | HowStuffWorks
March 8, 2023 - In the example code below, an array of 10 pointers to structures is declared, instead of declaring an array of structures. If an array of the structures had been created instead, 243 * 10 = 2,430 bytes would have been required for the array.
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ c-programming โ€บ structure-pointer
Structure Pointer in C Programming (With Examples)
March 18, 2026 - Learn in this tutorial about structure pointers in C with examples. Understand how to access and modify structure members using pointers in a clear & simple way.
๐ŸŒ
PrepBytes
prepbytes.com โ€บ home โ€บ c programming โ€บ structure pointer in c
Structure Pointer in C
December 28, 2023 - Explanation: In this example, a structure named "PrepBuddy" is defined with two members โ€“ "name" of type char and "age" of type int. A variable of this structure type named "person" is declared and initialized with some values.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ how-to-declare-pointer-to-struct-in-c
How to Declare a Pointer to a Struct in C? - GeeksforGeeks
July 23, 2025 - First, define a structure then declare a pointer to that structure using the below syntax and that pointer can be used to allocate and access memory for the structure. struct StructName *ptr ; or struct { // struct members } *ptr ; The below ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ what-are-pointers-to-structures-in-c-language
What are pointers to structures in C language?
September 14, 2023 - This is how you will define a new derived data type using the "struct" keyword โˆ’ ยท struct type { type var1; type var2; type var3; ... ... }; You can then declare a variable of this derived data type as following โˆ’
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Struct_(C_programming_language)
struct (C programming language) - Wikipedia
1 week ago - This is useful for passing a struct to a function to avoid the overhead of copying the struct. The -> operator dereferences the pointer (left operand) and accesses the value of a struct member (right operand).
Top answer
1 of 3
8

To answer your question rather directly, it's as if I asked you "why would I pass a variable as an argument to my function instead of just keeping it as a global variable?", but that's probably not the answer you're looking for, so here's some more insight on why pointers could be useful in this case:

Pointers are helpful because you can "move them around" more easily. Instead of having to copy over the whole stucture each time, you can just leave it where it is in memory and instead pass a pointer to it around.

Also, passing a pointer means you can modify "a" without having to copy it back, since the stucture resides in only one place in memory.

There are probably many more reasons that I've glossed over but these I think are the most important ones and the most relevant to your original question.

Have a nice day!

2 of 3
4

if your function was given as argument the struct without a pointer, its data would have to be copied to be used by the function which might take some time. Furthermore, if you want to modify the struct in the function and see its changes outside of the function's scope, your only option is to send it by pointer because you are giving the function the location in memory of the variable you want to modify and not a (local) copy. It is often preferred to send variables by value if they aren't big and you aren't modifying them because it makes the function's actions on its arguments clearer to the caller. If your function can only do an operation on a single variable, its use will be very limited. You could for instance use this same function with another xyz_t that the function can't directly access.

๐ŸŒ
Weber State University
icarus.cs.weber.edu โ€บ ~dab โ€บ cs1410 โ€บ textbook โ€บ 5.Structures โ€บ pointers.html
5.4. Structures And Pointers
They allow programmers to select the individual members or fields in a structure. The code fragment illustrates using the asterisk to define a pointer variable, the address-of operator, & to get the address of a local variable, s1, and the selection operators to access a structure's fields.
๐ŸŒ
Studytonight
studytonight.com โ€บ c โ€บ pointers-to-structure-in-c.php
C Language Pointer to Structure | Studytonight
But when we have a pointer of structure type, we use arrow -> to access structure members. #include <stdio.h> struct my_structure { char name[20]; int number; int rank; }; int main() { struct my_structure variable = {"StudyTonight", 35, 1}; struct my_structure *ptr; ptr = &variable; printf("NAME: %s\n", ptr->name); printf("NUMBER: %d\n", ptr->number); printf("RANK: %d", ptr->rank); return 0; }