answersLogoWhite

0

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

8y ago

What else can I help you with?

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 can you declare a pointer function?

*function();this declares a pointer function!


How is a structure type pointer variable declared in c?

struct thisorthat *ptr;


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);


Can you control ports through c plus plus?

Yes. If the ports are memory mapped, then you simply need a pointer to that address, and you need to declare the pointer as volatile. If they are I/O mapped, then you need to create an _asm{} block.


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

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