C syntax refers to the rules and structure governing the writing of programs in the C programming language.
Example:
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
Example Explained
#include <stdio.h>
: This line includes the standard input-output library (stdio.h
). This library provides functions likeprintf
andscanf
that are used for input and output operations.int main() { ... }
: This is the main function of the program. All C programs must have amain
function, and execution of the program starts from here. It returns an integer (int
) value, usually0
, to indicate the successful execution of the program.printf("Hello World!");
: This line prints the string"Hello World!"
to the standard output. Theprintf
function is used for formatted output, and"Hello World!"
is the format string that specifies the text to be printed.return 0;
: This line indicates the end of themain
function and returns an integer value0
to the calling environment (typically the operating system). This value indicates that the program executed successfully. Thereturn 0;
statement is optional in themain
function, but it’s good practice to include it for clarity.