First C program and Its Syntax

First C program and Its Syntax

08 Feb 2024
Beginner
1.05K Views
5 min read
Learn via Video Course & by Doing Hands-on Labs

C Programming For Beginners Free Course

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 or IDE 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 a main() 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 many printf() 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 the main() 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.
Summary
After getting through this article you must have at least got an idea to write a basic C program. You'll learn all the concepts of coding in C in the upcoming tutorials. Just follow the tutorial in a sequence. To become a certified C programmer, consider enrolling in our C Certification Program.
Share Article
Batches Schedule
About Author
Sakshi Dhameja (Author and Mentor)

She is passionate about different technologies like JavaScript, React, HTML, CSS, Node.js etc. and likes to share knowledge with the developer community. She holds strong learning skills in keeping herself updated with the changing technologies in her area as well as other technologies like Core Java, Python and Cloud.

Self-paced Membership
  • 22+ Video Courses
  • 750+ Hands-On Labs
  • 300+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Accept cookies & close this