Constants in Objective-C
Go supports constants of character, string, boolean, and numeric values.
const
declares a constant value. This can be a character, string, boolean, or numeric value.
In the main
function, we first print the string constant s
.
Constants can appear anywhere a variable can. We declare an integer constant n
and print it.
Constant expressions can perform arithmetic with arbitrary precision.
A numeric constant has no type until it’s given one, such as by an explicit conversion. Here, we convert the double constant to an int64_t
.
A number can be given a type by using it in a context that requires one, such as a variable assignment or function call. For example, sin
expects a double
.
To run the program, compile it with clang and then execute the binary.
Now that we can run and understand basic Objective-C constants, let’s learn more about the language.