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;
typedef int (*myfunptr)(int argc, char **argv);
myfunptr m= main;
char *ptr;
struct thisorthat *ptr;
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);
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.
// declare a function int* function(int, int); or int* (function)(int, int); // declare a pointer to a function int* (*pointer_to_function)(int, int);
ujkjkyjljlui kukhjkui
char *ptr;
int* pint; // instantiate a pointer to an int. float* pflt; // instantiate a pointer to a float.
It is a pointer that points to a member of a structure.
Not in C, no.
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;
struct thisorthat *ptr;
*function();this declares a pointer function!
#define NULL ((void *)0) /* defined in <stddef.h> */ const char *mynullvar = NULL;
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);
Nothing special: struct foo { void *ptr; };
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.