Pointers in Carbon language are similar to C++. The type of pointers-to-values-of-type-P is written as P*. Carbon pointers do not support pointer arithmetic.
What operations are supported by Pointers in Carbon?
Carbon pointers support
Dereferencing– given a pointer
*pgives the value
ppoints to as an l-value.
Address-of– given an l-value
&xreturns a pointer to
Note: There are no null pointers in Carbon. To represent a pointer that may not refer to a valid object, use the type
var p: i32 = 45; var pp: auto = *p; var ppp: auto = &pp;
Carbon Language Series
- Introduction to Carbon Language.
- How to define variables in Carbon.
- Primitive Types – Bool, Int, Float, String
- Tuple in Carbon
- Struct in Carbon
- Pointers in Carbon
- Operators in Carbon Language
- Conditions & Control Flow in Carbon
- Ternary Operator (if expression) in Carbon
- Switch conditional in Carbon using Match
- Loops in Carbon
- Functions in Carbon