Example CodeLines : C Syntax
HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

C Syntax


Syntax

C syntax refers to the set of rules that govern the writing of C programs. It's important to follow these rules to ensure your code is valid and can be understood by the compiler.



Example
              
              #include <stdio.h>  

                 int main()  
                 { 
                printf("Hello CodeLines!");
               return 0;
                 } 
You can click on above box to edit the code and run again.

Output


Hello CodeLines!

Example explained

"C example explained" typically refers to a code snippet or a small program written in the C programming language, accompanied by explanations of its components.

Line 1: #include <stdio.h> : This line is a preprocessor directive that tells the compiler to include the standard input/output library <(stdio.h)>.

Line 2: void greet(); : This is a function declaration for a function named greet. It indicates to the compiler that there will be a function named greet, which takes no arguments (void) and returns no value (void).

Line 3: printf("Hello, World!\n");: The printf function is used to print formatted output to the console. In this case, it displays the "Hello, World!" message followed by a newline (\n) character.

Line 4: int main() { /* ... */ } : The main function is the entry point of every C program. Execution begins from here. In this example, it calls the greet function and then returns 0, indicating successful execution.


Note that: Every C statement ends with a semicolon ;

Note: The body of int main() could also been written as:

int main(){printf("Hello CodeLines!");return 0;}

Remember: The compiler ignores white spaces. However, multiple lines makes the code more readable.

Line 5: return 0 ends the main() function.

Line 6: Do not forget to add the closing curly bracket } to actually end the main function.