About the Main() Function

<< Click to Display Table of Contents >>

Navigation:  Concordance Programming Fundamentals > Writing a Function >

About the Main() Function

As the name implies, the main() function is the main function of any CPL script. You must have a main() function for Concordance to run your script, and as such you really cannot do anything without it.

When you start your script, the main() function is the first place Concordance looks to start the execution of your program. In that sense, the main() function is like the first page of a book. A good practice is to always start writing your program by typing the following three lines.

main()

{

}

After you create the main function, you can then proceed to write the rest of your CPL. You can declare information outside the main() function, such as variables or other functions. For example, it is customary to declare all your other functions after main(). however, you can write your other functions anywhere in the CPL as long as they reside outside the main function.

The following example shows the main() function, with the Multiply_X_by_Y function declared afterwards. Note the use of comments, which consists of text within the /* and */ characters. These lines are ignored by the compiler, and therefore allow you to make remarks in your own code.

/* Here is the main function */

main()

{

   int myValue;

   int valOne;

   int valTwo;

 

   valOne = 10;

   valTwo = 5;

 

   myValue = Multiply_X_by_Y(valOne, valTwo);

}

 

/*Other functions get declared down here */

Multiply_X_by_Y(int x, int y)

{

   int z;

   z = x * y;

   return(z);
}