CKTIS / C
Operator ->: member access through a pointer
The -> operator selects a structure or union member through a pointer. The expression p->x corresponds to (*p).x and supports reading or, when the member is modifiable, writing. It does not validate the pointer.
Version: C23; repository compiler flag, production runtime not attested
Syntax
pointer_expression->member_nameThe -> operator selects a named member of the structure or union object pointed to by its left operand. The right operand is a member name of that type, not a variable containing a name. The result is an lvalue designating that member, not an independent copy.
Use point.x when you have an object and p->x when you have a pointer to it. The expression p->x corresponds to (*p).x; the parentheses are necessary because . binds more tightly than unary *.
Writing through -> is allowed only when the result is a modifiable lvalue. If p points to a const-qualified structure, the member accessed this way is also const-qualified. Accessing a member of an atomic structure or union object causes undefined behavior.
The operator does not check the pointer. When performing the access, it must point to an appropriate object whose lifetime has not ended; a null, uninitialized, or dangling pointer is unsuitable for this access. In the example, p->x = 7 changes point.x, so both reads print 7.
Examples
#include <stdio.h>
struct Point {
int x;
};
int main(void)
{
struct Point point = { .x = 3 };
struct Point *p = &point;
p->x = 7;
printf("%d %d\n", point.x, (*p).x);
return 0;
}
Result
7 7
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.