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

T*p;
T* p;
T *p;
T * p;

For example if T is int * then the pointer declaration can look like

int **p;
int ** p;
int * *p;
int * * p;

The same way you can declare a pointer to a structure

struct Card*p = &my_card;
struct Card* p = &my_card;
struct Card *p = &my_card;
struct Card * p = &my_card;

Pay attention to that you may write

T ( *p );

but you may not write

( T* ) p;

Also there exists another subtlety. If you will write for example

int* p1, p2

then the variable p1 has the type int * while the variable p2 has the type int instead of int *.

But if you will write

typedef int * T;

when in this declaration

T p1, p2;

the both variables have the type int *.

Answer from Vlad from Moscow on Stack Overflow
🌐
W3Schools
w3schools.com › c › c_structs_pointers.php
C Structs and Pointers
You want to avoid copying large amounts of data. Instead of copying a whole struct, you can just pass a pointer.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › structure-pointer-in-c
Structure Pointer in C - GeeksforGeeks
A structure pointer is a pointer variable that stores the address of a structure. It allows the programmer to manipulate the structure and its members directly by referencing their memory location rather than passing the structure itself.
Published   December 23, 2024
Discussions

How can I declare a Pointer to a struct in C? - Stack Overflow
I have learned that pointers can be declared in 3 different ways: int* a; int *b; int * c; I prefer: int* a; While declaring a pointer to a structure, is it correct to write it like following: st... More on stackoverflow.com
🌐 stackoverflow.com
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
why use pointer to struct and not use the struct directly (C) - Stack Overflow
I have two examples shown in the code below, which gives the same result. I see people do example 1 using pointer. But why not do example 2 and using the a.x directly? is there any difference? ty... More on stackoverflow.com
🌐 stackoverflow.com
Pointer to struct VS. nested struct
If thing2 is used independently of thing1, then it can be cleaner to use a pointer so you don't have to pass thing1 around wherever you need thing2. Also if thing2 is needed in more than one other struct you'll have to use pointers. More on reddit.com
🌐 r/C_Programming
12
12
April 4, 2019
🌐
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
🌐
Programiz
programiz.com › c-programming › c-structures-pointers
C structs and Pointers (With Examples)
In this tutorial, you'll learn to use pointers to access members of structs. You will also learn to dynamically allocate memory of struct types with the help of examples.
🌐
Swarthmore College
cs.swarthmore.edu › ~newhall › cs31 › resources › C-structs_pointers.php
CS31: Intro to C Structs and Pointers
See struct.c for more examples. Exercise: implement and test two functions in this file: printStudent and initStudent. C pointer variables A pointer variable stores the address of a memory location that stores a value of the type to which it points ("a level of indirection").
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_pointers_to_structures.htm
Pointers to Structures in C
A pointer to struct is thus a variable that refers to a struct variable. 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 ...
🌐
Scaler
scaler.com › home › topics › pointers with structures in c
Pointers and Structures in C - Scaler Topics
June 10, 2022 - Here, we have created a user-defined data type, User using the struct keyword, this structure has three members that are name (string), age (int), and role (string). To store information of two users, we have declared two structure variables user_1 and user_2 of type User and later initialized and accessed their value in the main() function using the variable name and dot (.) operator. As shown in the above figure, a structure pointer stores the memory address of a structure variable.
🌐
HowStuffWorks
computer.howstuffworks.com › tech › computer software › programming
Pointers to Structures - The Basics of C Programming | HowStuffWorks
March 8, 2023 - You deal with *r just like a normal structure variable, but you have to be careful with the precedence of operators in C. If you were to leave off the parenthesis around *r the code would not compile because the "." operator has a higher precedence than the "*" operator. Because it gets tedious to type so many parentheses when working with pointers to structures, C includes a shorthand notation that does exactly the same thing:
🌐
Unstop
unstop.com › home › blog › structure pointer in c | create, uses & more (+code examples)
Structure Pointer In C | Create, Uses & More (+Code Examples)
July 26, 2024 - You can read more about structures here: Structure In C | Create, Access, Modify & More (+Code Examples) In simple terms, a structure pointer in C is a pointer that specifically points to a structure.
🌐
Reddit
reddit.com › r/c_programming › what is the difference between structs and pointer to structs?
r/C_Programming on Reddit: What is the difference between structs and pointer to structs?
August 21, 2021 -

frighten grey forgetful stupendous light heavy paltry flowery groovy roll

This post was mass deleted and anonymized with Redact

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.

🌐
Programiz
programiz.com › cpp-programming › structure-pointer
C++ Pointers to Structure (With Examples)
Since pointer ptr is pointing to variable d in this program, (*ptr).inch and d.inch are equivalent. Similarly, (*ptr).feet and d.feet are equivalent. Since the . operator has a higher precedence than the * operator, we enclose *ptr in brackets when using (*ptr).inch. We can use the arrow (->) operator to access member variables and member functions of a structure ...
🌐
Redixhumayun
redixhumayun.github.io › databases › 2026 › 04 › 14 › zero-copy-pages-in-rust.html
Zero-Copy Pages in Rust: Or How I Learned To Stop Worrying And Love Lifetimes | Zaid Humayun’s Blog
3 weeks ago - The version I went with flips this around.The old computer science move: “Any problem in computer science can be solved with another level of indirection”. To make that concrete, a slotted page is divided into the header, the line pointers and the record space, so we’ll store those parsed references in HeapPage and keep the PageReadGuard in HeapPageView. pub struct HeapHeaderRef<'a> { bytes: &'a [u8], } struct LinePtrBytes<'a> { bytes: &'a [u8], } struct LinePtrArray<'a> { bytes: LinePtrBytes<'a>, len: usize, capacity: usize, } struct HeapRecordSpace<'a> { bytes: &'a [u8], base_offset: usize, } struct HeapPage<'a> { header: HeapHeaderRef<'a>, line_pointers: LinePtrArray<'a>, record_space: HeapRecordSpace<'a>, } pub struct HeapPageView<'a> { guard: PageReadGuard<'a>, layout: &'a Layout, }
🌐
Corsix
corsix.org › content › simplified-model-of-fil-c
A simplified model of Fil-C
2 weeks ago - Things become more interesting when the value being stored or loaded is itself a pointer. As already seen, local variables of pointer type have their accompanying AllocationRecord* variable inserted by the compiler, which the compiler can do because it has full control and visibility of all local variables.
🌐
W3Schools
w3schools.com › c › c_structs.php
C Structures (structs)
To access the structure, you must create a variable of it. Use the struct keyword inside the main() method, followed by the name of the structure and then the name of the structure variable:
🌐
Quora
quora.com › Why-do-we-use-a-struct-pointer-inside-a-structure-definition-in-C
Why do we use a struct pointer inside a structure definition in C? - Quora
Forward declaration: to use a pointer to a struct type inside its own definition you must forward-declare the type: Example: typedef struct Node Node; struct Node { int value; Node *next; }; ... Nodes created with malloc/free for dynamic lifetimes.
🌐
Wikipedia
en.wikipedia.org › wiki › Struct_(C_programming_language)
struct (C programming language) - Wikipedia
February 8, 2026 - In the C programming language, struct (referring to a structure) is the keyword used to define a composite, a.k.a. record, data type – a named set of values that occupy a block of memory. It allows for the different values to be accessed via a single identifier, often a pointer.
🌐
Weber State University
icarus.cs.weber.edu › ~dab › cs1410 › textbook › 5.Structures › pointers.html
5.4. Structures And Pointers
Takes the address of s1 and saves it in a structure pointer named sp1. Creates a new structure object dynamically on the heap with new and stores the address in a structure pointer named sp2.