OC Winning Volume type
The most basic form of a variable is a scalar, which is a variable that can store only one value at a time.
integers, floating-point numbers, and characters are scalar. Scalars have different predefined memory spaces and the size of the values that can be stored. You should be aware of these types of restrictions before deciding what type to define variables for. Nsinteger and Nsuinteger types are available, and they can be automatically converted between 32-bit or 64-bit based on the architecture of our compiled platform.
int unsigned int
Float Double
Long Long Long
Char
BOOL
Nsinteger Nsuinterger
Special variable Modifiers
In addition to variable types and variable names, there are some keywords that are used to decorate the type of variables you declare. One of the most important modifier keywords is the static and const you will see in this book.
As I mentioned earlier, when declaring a local variable, the memory of the variable is usually allocated each time the program enters the scope of the local variable and is freed when it leaves. This type of storage is called automatic storage or is decorated with the default modifier keyword auto.
The static keyword allocates memory when declaring a variable, so only one memory is allocated once during the program's run. When the variable is accessed in the program, it is actually accessing the previously allocated memory. This is important because you can specify a local variable to hold the value for a long time. This is useful for storing local variables that are created with a large amount of resources and that do not change very often. Listing 2-7 shows how to use the static keyword in a function to optimize expensive operations such as initializing variables.
The register modifier is used to prompt the compiler to store data that will be accessed frequently and is therefore suitable for storing in registers in the CPU. This keyword is seldom used.
extern the modifier indicates that the defined function or declared variable refers to an actual variable or function that is defined or assigned in another compilation unit of the application.
The Const keyword also modifies the memory behavior of the declared variable, but in this case, the variable is read-only. This means that 13
After the variable is initialized, its value cannot be changed. This is useful when declaring variables that cannot be modified, such as constants.
Scalar and modifier