Выбрать главу

3.1.2 Beginning and Ending of a Program

In C language, a program begins with the keywords:

void main()

After this, a curly opening bracket is used to indicate the beginning of the program body. The program is terminated with a closing curly bracket. Thus, as shown in Figure 3.1, the program has the following structure:

void main() {

 program body

}

3.1.3 Terminating Program Statements

In C language, all program statements must be terminated with the semicolon (“;”) character; otherwise a compiler error will be generated:

j = 5; // correct

j = 5 // error

3.1.4 White Spaces

White spaces are spaces, blanks, tabs, and newline characters. The C compiler ignores all white spaces. Thus, the following three sequences are identicaclass="underline"

int i;  char j;

or

int i;

char j;

or

int i;

      char j;

Similarly, the following sequences are identicaclass="underline"

i = j + 2;

or

i = j

     + 2;

3.1.5 Case Sensitivity

In general, C language is case sensitive and variables with lowercase names are different from those with uppercase names. Currently, however, mikroC variables are not case sensitive (although future releases of mikroC may offer case sensitivity) so the following variables are equivalent:

total TOTAL Total ToTal total totaL

The only exception is the identifiers main and interrupt, which must be written in lowercase in mikroC. In this book we are assuming that the variables are case sensitive, for the sake of compatibility with other C compilers, and variables with the same name but different cases are not used.

3.1.6 Variable Names

In C language, variable names can begin with an alphabetical character or with the underscore character. In essence, variable names can include any of the characters a to z and A to Z, the digits 0 to 9, and the underscore character “_”. Each variable name should be unique within the first 31 characters of its name. Variable names can contain uppercase and lowercase characters (see Section 3.1.5), and numeric characters can be used inside a variable name. Examples of valid variable names are:

Sum count sum100 counter i1 UserName

_myName

Some names are reserved for the compiler itself and cannot be used as variable names in a program. Table 3.1 gives a list of these reserved names.

Table 3.1: mikroC reserved names

asm enum signed
auto extern sizeof
break float static
case for struct
char goto switch
const if typedef
continue int union
default long unsigned
do register void
double return volatile
else short while

3.1.7 Variable Types

The mikroC language supports the variable types shown in Table 3.2. Examples of variables are given in this section.

Table 3.2: mikroC variable types

Type Size (bits) Range
unsigned char 8 0 to 255
unsigned short int 8 0 to 255
unsigned int 16 0 to 65535
unsigned long int 32 0 to 4294967295
signed char 8 –128 to 127
signed short int 8 –128 to 127
signed int 16 –32768 to 32767
signed long int 32 –2147483648 to 2147483647
float 32 ±1.17549435082E-38 to ±6.80564774407E38
double 32 ±1.17549435082E-38 to ±6.80564774407E38
long double 32 ±1.17549435082E-38 to ±6.80564774407E38
(unsigned) char or unsigned short (int)

The variables (unsigned) char, or unsigned short (int), are 8-bit unsigned variables with a range of 0 to 255. In the following example two 8-bit variables named total and sum are created, and sum is assigned decimal value 150: