while writing c basic things you should kept in your mind. The syntax below showing right and wrong way to write c. printf() function in c is used to print the output of a program. The quotes tell the compiler that you want to output the literal string .
/*this syntax is about declaring of variable at the right position .int signifies that variable is integer type */
Wrong Syntax…
#include <stdio.h>
int main()
{
/* wrong! The variable declaration must appear first */
printf( “Declare x next” );
int x;
return 0;
}
Correct Syntax..
#include <stdio.h>
int main()
{
int x;
printf( “Declare x first” );
return 0;
}
Let us now discuss this simple syntax.In first line you will see the “#include” which is a “preprocessor” directive that tells the compiler to put code from the header file called stdio.h into our program before actually creating the executable.
By including header files, you can gain access to many different functions–both the printf and getchar functions are included in stdio.h.
The next line is int main(). This line tells the compiler that there is a function named main, and that the function returns an integer, hence int. The “curly braces” ({ and }) signal the beginning and end of functions and other code blocks. A function is simply a collection of commands that do “something”. The main function is always called when the program first executes. From main, we can call other functions, whether they be written by us or by others or use built-in language features. To access the standard functions that comes with your compiler, you need to include a header with the #include directive.
The semicolon is part of the syntax of C. It tells the compiler that you’re at the end of a command.
Finally, at the end we return a value from main to the operating system by using the return statement. This return value is important as it can be used to tell the operating system whether our program succeeded or not. A return value of 0 means success.
