Sunday, August 6, 2017

C programming; Lesson 1: Main program and definition of variables

The simplest program in C would be:
int main () {
return 0;
}
main is the name for the main function in each C program and every program written in C must have exactly one main function. It should be noted that this is only a symbolic name that gives the compiler an idea of which part of the program to start running first.
The word int in front of the tag of the main function indicates that the main () after the completion of the commands and functions contained therein will return a whole number (integer) as a result of this execution. As the main program runs from the operating system, the result of the main program is returned to the operating system. Most often, this is a code that signals an error occurring during a program run or a notification of a successful execution.

Behind the word main follows the open-closed bracket. Within these brackets should come data descriptions that are transmitted from the operating system to main (). These data are called function arguments. In this example of the program no arguments are transmitted.

After that comes an open left brace that marks the beginning of a block in which the main function commands will be located, while a closed, right brace at the bottom line indicates the end of that block. Within the braces of the the program there is a return 0, which means that the main program returns the number 0, which is a message to the operating system that the program has been successfully completed, whatever his function was.
Sign ; after returns 0 indicates the end of the command and serves as a message to the compiler that all the following characters interpret as a new command.
Another example of the program is:

#include <stdio.h>

int main () {
printf ("These are Exercises");
return 0;
}

In this example there is a command #include <stdio.h> which requires the compiler to include the stdio.h library in our program. In this library, there is an output stream of functions that allows you to print data on the screen. It is necessary to emphasize that include is not a C command, but it is a preprocessor command. After finding it, the translator will stop the process of translating the code into the current file, jump to stdio.h, translate it, and then return to the translation in the startup file.





1 comment: