The basic syntax of a C program consists of a few key elements, including
Preprocessor directives: These begin with the # symbol and provide instructions to the compiler, such as including libraries or defining constants.
Function declaration: A C program usually begins with a declaration of the main() function, which is the starting point of the program.
Variables and data types: C requires variables to be declared with a specific data type, such as int, float, or char.
Statements and expressions: Statements are individual instructions or commands, while expressions are combinations of variables and operators that produce a value.
Control structures: These include if/else statements, loops, and switch/case statements that allow the program to make decisions and repeat certain blocks of code.
Functions: C programs are usually composed of one or more functions, which contain blocks of code that perform specific tasks.
Comments: Comments are used to provide explanations or documentation within the code.
Here is an example of a simple C program that prints “Hello, world!” to the console.
#include <stdio.h>
int main()
{
printf("Hello, world!");
return 0;
}
Note :- This program includes a preprocessor directive to include the stdio.h library, declares the main() function, and uses the printf() function to print the message to the console.