Page 29 - C-Language
P. 29

See more about headers.


         int main(void)


        This line starts the definition of a function. It states the name of the function (main), the type and
        number of arguments it expects (void, meaning none), and the type of value that this function
        returns (int). Program execution starts in the main() function.


         {
             …
         }


        The curly braces are used in pairs to indicate where a block of code begins and ends. They can be
        used in a lot of ways, but in this case they indicate where the function begins and ends.


             puts("Hello, World");


        This line calls the puts() function to output text to standard output (the screen, by default), followed
        by a newline. The string to be output is included within the parentheses.


        "Hello, World" is the string that will be written to the screen. In C, every string literal value must be
        inside the double quotes "…".

        See more about strings.


        In C programs, every statement needs to be terminated by a semi-colon (i.e. ;).


             return 0;


        When we defined main(), we declared it as a function returning an int, meaning it needs to return
        an integer. In this example, we are returning the integer value 0, which is used to indicate that the
        program exited successfully. After the return 0; statement, the execution process will terminate.


        Editing the program




        Simple text editors include vim or gedit on Linux, or Notepad on Windows. Cross-platform editors
        also include Visual Studio Code or Sublime Text.


        The editor must create plain text files, not RTF or other any other format.


        Compiling and running the program




        To run the program, this source file (hello.c) first needs to be compiled into an executable file (e.g.
        hello on Unix/Linux system or hello.exe on Windows). This is done using a compiler for the C
        language.




        https://riptutorial.com/                                                                                5
   24   25   26   27   28   29   30   31   32   33   34