C is structured. So, it is modular and the modules are function, i.e. the modules are called function. One of the functions must be called main. The program will always begin by executing the main function, which may access other functions.
To run a c program, you must include something at the beginning of the code, which will ensure your smooth compiling. It is sort of mandatory because this loads some initial code to run a program. For example;
#include <stdio.h>
The #include is a "preprocessor" directive that loads a file called stdio.h (stdio.h is a header file). Header files are collection of some build-in codes that does a lot of task to run a program.
Now look at the below program;
#include <stdio.h>
int main()
{
printf("Hello,World");
return 0;
//end of code(this is a comment)
}
So the whole program is enclosed by a function and this function is called 'main()'.
In later tutorial, you will learn about details of functions, how to write function, how to use it, what are required to write a function.
Codes are written in an enclosed pair of braces, i.e., { }
Inside braces expression statements are written, i.e.,
printf("Hello,World");
Each expression statement must end with a semicolon (;).
Comments (remarks) may appear anywhere within a program, as long as they are placed within the delimiters /* and */ (e.g., /* this is for multiple comment */). Single line comment can be written after two forward slashes //.
The program is typed in lowercase. Either upper- or lowercase can be used, though it is customary to type
ordinary instructions in lowercase.
No comments:
Post a Comment