Pointers in Carbon Language

pointers in carbon language

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 and Address-of

  1. Dereferencing – given a pointer p, *p gives the value p points to as an l-value. p->m same as (*p).m.
  2. Address-of – given an l-value x, &x returns a pointer to x.

Note: There are no null pointers in Carbon. To represent a pointer that may not refer to a valid object, use the type Optional(P*).

Code Example

var p: i32 = 45;
var pp: auto = *p;
var ppp: auto = &pp;

Sign Up for Our Newsletters

Get only the best articles delivered to your mail

You May Also Like
introduction to carbon language - what and why it is created

Introduction to Carbon Language

Table of Contents Hide IntroductionFeatures of Carbon LanguageWhy developed Carbon? Why not upgraded C++?Where Carbon could be used?Carbon is written in which language?Code Example Carbon Language is the successor to…
View Post
functions in carbon language

Functions in Carbon Language

Table of Contents Hide IntroductionCode Example –Conclusion Functions in carbon language has the same role as in C, Php or any other functional language. It is used to separate a…
View Post