22
DecFirst C program and Its Syntax
First C Program and Its Syntax: An Overview
Are you excited to begin coding in C? But, don't know where and how to start? Don't worry. All your questions will be answered in this article today. You will understand to write a C program in a step-by-step manner. If you want to deepen your understanding of C programming skills, consider enrolling in our C Online Training. In this article of C Tutorial, we'll learn the syntax and the meaning of each word or symbol in the C program.Begin your 1st C Program
- Open any
text editor
orIDE
and create a new file with any name with a.C
extension. e.g.helloworld.c
- Open the file and enter the below code:
#include <stdio.h> int main() { printf("Hello, World!"); return 0; }
- Compile and run the code
Output
Hello, World!
Read More - Top 50 Mostly Asked C Interview Questions
Syntax of C
In the above section, you tried the very basic program of “Hello World” in C. Did you understand the terms like stdio.h
, printf
written in the code? Don’t worry let us understand it one by one:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
- In the very first line,
#include
signifies the header file. This header file is a library of C that contains standard input-output functions. In the above code printf()
function belongs to the stdio.h
header file. - In the next line, we have the
main()
function. It is the function due to which the program executes. Any C program without amain()
function cannot run. Only the code written within{}
executes during run time. - With the help of
printf()
function our program printed the sentence “hello world” on the screen. There can be as manyprintf()
statements as many you want in your program.
#include <stdio.h>
int main() {
printf("Hello, World!");
printf("This is my first program");
return 0;
}
Output
Hello, World!This is my first program
return 0
indicates the end of the main function.- The closing curly bracket “
}
” is used to actually end the main function. - Have you noticed “
;
” after each line of code in themain()
function? It is necessary to put it after each line of code. In C every line ends with a “;
”. If you forget to put a “;
”, it will show you a compile-time error. - C ignores white spaces but we use it to make the code more readable.