answersLogoWhite

0


Best Answer

It depends on whether you've declared a type alias or not. Without an alias, you must include the struct keyword:

struct record {

// ...

};

struct record* ptr; // declare a pointer to struct record

With an alias, the struct keyword can be omitted from the type name. By convention, we use the _t suffix to denote the type name. Typically, aliases are declared as part of the type declaration:

typedef struct record_t { // type name

// ...

} record; // alias

record* p; // declare a pointer to record

Note that record is the alias while struct record_t is the data type associated with that alias. We can use the type or the alias as we see fit, however type aliases are more convenient.

We can also declare pointer aliases in the type declaration:

typedef struct record_t {

// ...

} record, *record_ptr;

record_ptr p; // declare a pointer to record

However, this latter technique is best avoided because we can often end up inadvertently declaring pointer to pointer types instead of pointers:

record_ptr* p; // equivalent to: record** p; -- possibly erroneous

Note that you cannot use a type alias within a self-referential data type, such as a node with embedded pointers to other nodes (as used in linked list implementations):

typedef struct node_t {

int data;

node* next; // error: node is not (yet) defined

node* prev; // error: node is not (yet) defined

} node;

To fix these errors, use the actual type name:

typedef struct node_t {

int data;

struct node_t* next;

struct node_t* prev;

} node;

User Avatar

Wiki User

7y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

typedef int (*myfunptr)(int argc, char **argv);

myfunptr m= main;

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you declare a pointer to a structure in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you declare pointer in c?

ujkjkyjljlui kukhjkui


How do you declare a pointer to a character string in c?

char *ptr;


How do you declare a pointer variable in c?

int* pint; // instantiate a pointer to an int. float* pflt; // instantiate a pointer to a float.


What is pointer to a member in objective c?

It is a pointer that points to a member of a structure.


32 can you create a linked list with out structure pointer?

Not in C, no.


How can one create a pointer to structure in C?

Create a pointer of the type (pointer to struct) and assign the address of an instance of the structure to your pointer: typedef struct x { /* ... */ }; struct x my_structure; struct x* ptr = &my_structure;


How is a structure type pointer variable declared in c?

struct thisorthat *ptr;


How can you declare a pointer function?

*function();this declares a pointer function!


How will you declare null pointer in C?

#define NULL ((void *)0) /* defined in <stddef.h> */ const char *mynullvar = NULL;


What does two asterisks mean in C?

It means to declare or dereference a pointer to a pointer. For example: int x = 5; int *xPtr = &x; int **xPtrPtr = &xPtr; printf("%d\n", **xPtrPtr);


How will you implement a function pointer inside a structure in c?

Nothing special: struct foo { void *ptr; };


What is the difference between structure and pointer?

A structure is a collection of primitives or other structures. A pointer is a memory address. Comparison of the two is like comparing bowling balls to cinder blocks. You can say that a structure defines the layout of the data, while a pointer points to data that is a particular structure.