First C program and Its Syntax

First C program and Its Syntax

27 May 2024
Beginner
2.6K 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

Live Classes Schedule

Our learn-by-building-project method enables you to build practical/coding experience that sticks. 95% of our learners say they have confidence and remember more when they learn by building real world projects.
ASP.NET Core Certification Training Jul 15 MON, WED, FRI
Filling Fast
07:00AM to 08:30AM (IST)
Get Details
Advanced Full-Stack .NET Developer Certification Training Jul 15 MON, WED, FRI
Filling Fast
07:00AM to 08:30AM (IST)
Get Details
Azure Master Class Jul 20 SAT, SUN
Filling Fast
03:00PM to 05:00PM (IST)
Get Details
ASP.NET Core Certification Training Jul 28 SAT, SUN
Filling Fast
07:00AM to 09:00AM (IST)
Get Details
Software Architecture and Design Training Jul 28 SAT, SUN
Filling Fast
05:30PM to 07:30PM (IST)
Get Details
.NET Solution Architect Certification Training Jul 28 SAT, SUN
Filling Fast
05:30PM to 07:30PM (IST)
Get Details
Azure Developer Certification Training Jul 28 SAT, SUN
Filling Fast
10:00AM to 12:00PM (IST)
Get Details
Advanced Full-Stack .NET Developer Certification Training Jul 28 SAT, SUN
Filling Fast
07:00AM to 09:00AM (IST)
Get Details
Data Structures and Algorithms Training with C# Jul 28 SAT, SUN
Filling Fast
08:30PM to 10:30PM (IST)
Get Details
Angular Certification Course Aug 11 SAT, SUN
Filling Fast
09:30AM to 11:30AM (IST)
Get Details
ASP.NET Core Certification Training Aug 24 SAT, SUN
Filling Fast
07:00AM to 09:00AM (IST)
Get Details

Can't find convenient schedule? Let us know

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
  • 800+ Hands-On Labs
  • 400+ 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