Curriculum
Course: C basic
Login

Curriculum

C basic

C Introduction

0/1

C Get Started

0/1

C Comments

0/1

C Constants

0/1

C Operators

0/1

C Break and Continue

0/1

C User Input

0/1

C Memory Address

0/1

C Structures

0/1
Text lesson

C Syntax

Syntax

You’ve encountered the following code several times in the initial chapters. Let’s dissect it to enhance comprehension.

Example

#include <stdio.h>

int main() {
  printf(“Hello World!”);
  return 0;
}

Example explained

Line 1, #include <stdio.h>, is a library header file enabling the utilization of input and output functions like printf() (employed in line 4).

These header files augment the capabilities of C programs.

If the mechanism of #include <stdio.h> seems unclear, don’t fret. Simply consider it as a standard inclusion that is nearly ubiquitous in your program structure.

Line 2: A blank line serves to enhance code readability; although C disregards white space, we employ it for clarity.

Line 3: Another constant in C programs is main(), referred to as a function. Any code enclosed within its curly braces {} will execute.

Line 4: printf() is a function utilized for displaying or printing text on the screen. In our instance, it will output “Hello World!”.

Please be aware that in C, every statement is terminated by a semicolon (;).

Keep in mind that the body of the int main() function can alternatively be expressed as follows:

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

Bear in mind that while the compiler disregards white spaces, using multiple lines enhances code readability.

Line 5: The statement return 0 concludes the main() function.

Line 6: Ensure to include the closing curly bracket } to formally conclude the main function.