Initialization

The initial value of a declared object can be set at the time of declaration (initialization). A part of the declaration which specifies the initialization is called initializer.

Initializers for globals and static objects must be constants or constant expressions. The initializer for an automatic object can be any legal expression that evaluates to an assignment-compatible value for the type of the variable involved.

Scalar types are initialized with a single expression, which can optionally be enclosed in braces. The initial value of an object is that of the expression; the same constraints for type and conversions as for simple assignments are applied to initializations too.

For example:

int i = 1;
char *s = "hello";
struct complex c = {0.1, -0.2};
// where 'complex' is a structure (float, float)

For structures or unions with automatic storage duration, the initializer must be one of the following:

For example:

struct dot {int x; int y; } m = {30, 40};

For more information, refer to Structures and Unions.

Also, you can initialize arrays of character type with a literal string, optionally enclosed in braces. Each character in the string, including the null terminator, initializes successive elements in the array. For more information, refer to Arrays.

Automatic Initialization

The mikroC PRO for PIC32 does not provide automatic initialization for objects. Uninitialized globals and objects with static duration will take random values from memory.

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code