How to define variables in carbon language?

Total
0
Shares
how to define variables in carbon language

To define variables in carbon language, use this syntax –

var identifier: < expression | auto > [ = value ];

Code Example

var x: i32 = 42;

Let’s understand this example –

  • var – To indicate that this is a variable.
  • x – Name of the variable
  • i32 – 32 bit integer
  • : – To separate variable name and it’s type
  • 42 – Value of the variable

We can also write this code using auto

var x: auto = 42;

auto results in a constant IntLiteral(42) value.