C Basic Syntax - GeeksforGeeks (2024)

Last Updated : 16 Jun, 2023

Comments

Improve

C is a procedural programming language. It was developed by Dennis Ritchie at the Bell Laboratories in the year 1972. Despite being old C is a very popular language among programmers. It is a very fast language compared to other languages like Python, Java, etc.

Below is the basic syntax structure of the C program:

C Basic Syntax - GeeksforGeeks (1)

The basic syntax of the C program consists of the header, main() function, variable declaration, body, and return type of the program.

  • The header is the first line in the C program with extension .h which contains macro definitions and C functions.
  • Programs must contain the main() function because execution in C programming starts from the main().
  • Variable declaration in C is done inside the main function and can be used in the body anywhere but before the main, we can also declare variables which are known as Global variables.
  • In the body of the function, we perform operations required inside the function like printing, sum, average, sorting, searching, etc.
  • The last part of the C program is the return statement which refers to returning values of the program. If the return type is void then there will be no return statement.

C

// Basic Syntax of C Program

#include <stdio.h>

// main function

int main()

{

// body

printf("Hi! This is a basic C program.");

// return statement

return 0;

}

Output

Hi! This is a basic C program.

Tokens

A token in C programming is either a keyword, an identifier, a constant, a string literal, or a symbol. Let’s get a good understanding of tokens through a print statement in C language.

printf("GeeksforGeeks\n");

Individual tokens from the above syntax are:

printf("GeeksforGeeks\n");

Semicolons

In C programming Semicolon is used to show the termination of Instruction. It is also called a statement terminator since every single statement should be ended with a semicolon. Semicolons are used to end statements in C.

The Semicolon tells the compiler that the current statement has been terminated. If any statement in the Program ends without a semicolon, then the program will not compile and will generate an error message.

C

// C program to demonstrate use of Semicolon

#include <stdio.h>

int main() { printf("GeeksforGeeks") return 0; }

Error

./253df686-61b0-495f-98fe-46dfeb318172.c: In function 'main':./253df686-61b0-495f-98fe-46dfeb318172.c:7:5: error: expected ';' before 'return' return 0; ^

Preprocessor Directives

In C language, a program should begin with preprocessor directives since they contain multiple files that contain specific functions. Preprocessors in C are used to process our source code before compilation.

There are 4 main types of Preprocessor directives in C:

  1. Macros
  2. File inclusion
  3. Conditional Compilation
  4. Other directives

While executing a program in C multiple steps are involved as mentioned below:

C Basic Syntax - GeeksforGeeks (2)

Identifiers in C

In C programming, the identifier is used to identify a variable, function, or any other user-defined data type. C programming language does not allow special characters such as $, @, or % within the identifier.

C is a case-sensitive programming language which means that “geeksforgeeks” and “Geeksforgeeks” are treated as two different identifiers in C. Identifiers should begin with a letter Uppercase letters (A to Z), lowercase letters (a-z), digits (0-9) or underscores ( _ ).

Some examples of identifiers in C are:

geeksGeekgeek12_geek
g_f_gG_f_2_geek89geeksforgeeks
GEEKSFORGEEKSGEEKS_for_9081gfg_69g23gf9

C Keywords

In the C programming language, keywords are reserved words that have special meanings. These reserved words can’t be used as variables or constants or any other identifier name. C contains a total of 32 keywords that are reserved and have special meanings.

Keywords in C programming are mentioned below:

intlongshortsigned
unsignedvoidcharbreak
registerstructureclassvolatile
whileforswitchtypedef
unionstaticautoreturn
caseconstcontinuedefault
dodoubleelseif
enumexternfloatgoto

Comments in C

In C programming Comments are used to make any program more readable and understandable. Comments are generally used by programmers to add explanations or descriptive text in the code without any interference from the compiler or the programming structure.

Comments are not programming statements and they are ignored by the compiler. We can’t have comments inside comments since they will interfere within themselves.

In C language there are two types of programming comments:

  • Single-line Comments: Single-line comments begin with // and they are only used for a single line and end in the next line.
  • Multiline Comments: Multi-line comments start with /* and end with */. They can be a single line or multiline.

Example

C

// C Program to demonstrate the comments

#include <stdio.h>

int main()

{

// This is a single line comment

/*

This is a multiline comment

used in this program

*/

printf("GeeksforGeeks");

return 0;

}

Output

GeeksforGeeks

In the above C program, comments are ignored by the compiler and they can be read only by the programmer.

Whitespaces in C

In C programming lines containing white spaces, blank lines, and comments are ignored by the compiler. Whitespace in C is used to describe blanks, newline characters, comments, and tabs.

Whitespace is used to separate parts of a statement from another and it helps the compiler to distinguish the keywords, identifiers, and elements in a statement. It allows us to format our code in a way that makes it easier to understand by programmers and others. In C we are free to use the whitespaces to increase user readability.

Example of Whitespace in C:

int a;// whitespace used to increase readablity and to distinguish elements.string s = "GeeksforGeeks";

Functions

In C programming Function is a set of statements that performs specific computations. Functions help us to reduce our code redundancy. Instead of writing multiple lines of code again and again we use functions to reduce code redundancy.

Functions in C provide abstractions. In C “main” is also a function that has its own return type defined in the program. This function serves as the starting point for program execution.

Syntax

return_type function_name(parameter_list) { // Function body (code goes here)}

Example

int mul(int Full_marks,int Full_marks2);

Below is the representation of the above C function:

C Basic Syntax - GeeksforGeeks (3)



kamleshjoshi18

C Basic Syntax - GeeksforGeeks (5)

Improve

Next Article

Basic Input and Output in C

Please Login to comment...

C Basic Syntax - GeeksforGeeks (2024)
Top Articles
Today's Final Jeopardy Clue
2024 Volleyball Roster
Kathleen Hixson Leaked
Www.fresno.courts.ca.gov
Hannaford Weekly Flyer Manchester Nh
Odawa Hypixel
Maria Dolores Franziska Kolowrat Krakowská
Frank Lloyd Wright, born 150 years ago, still fascinates
Professor Qwertyson
Terraria Enchanting
Recent Obituaries Patriot Ledger
How To Get Free Credits On Smartjailmail
Bloxburg Image Ids
How Far Is Chattanooga From Here
Displays settings on Mac
270 West Michigan residents receive expert driver’s license restoration advice at last major Road to Restoration Clinic of the year
Espn Expert Picks Week 2
Culver's Flavor Of The Day Monroe
How Quickly Do I Lose My Bike Fitness?
What to do if your rotary tiller won't start – Oleomac
Kris Carolla Obituary
[Birthday Column] Celebrating Sarada's Birthday on 3/31! Looking Back on the Successor to the Uchiha Legacy Who Dreams of Becoming Hokage! | NARUTO OFFICIAL SITE (NARUTO & BORUTO)
Find Such That The Following Matrix Is Singular.
Swedestats
CANNABIS ONLINE DISPENSARY Promo Code — $100 Off 2024
Milanka Kudel Telegram
Putin advierte que si se permite a Ucrania usar misiles de largo alcance, los países de la OTAN estarán en guerra con Rusia - BBC News Mundo
Aes Salt Lake City Showdown
Rogue Lineage Uber Titles
897 W Valley Blvd
Mchoul Funeral Home Of Fishkill Inc. Services
Greyson Alexander Thorn
Craigslistodessa
The Mad Merchant Wow
My.lifeway.come/Redeem
Elisabeth Shue breaks silence about her top-secret 'Cobra Kai' appearance
Invalleerkracht [Gratis] voorbeelden van sollicitatiebrieven & expert tips
Clausen's Car Wash
Mississippi weather man flees studio during tornado - video
Alston – Travel guide at Wikivoyage
Craigslist Woodward
My Eschedule Greatpeople Me
Borat: An Iconic Character Who Became More than Just a Film
Best Haircut Shop Near Me
Sara Carter Fox News Photos
How the Color Pink Influences Mood and Emotions: A Psychological Perspective
Mejores páginas para ver deportes gratis y online - VidaBytes
Arginina - co to jest, właściwości, zastosowanie oraz przeciwwskazania
Minute Clinic Mooresville Nc
Electric Toothbrush Feature Crossword
Where To Find Mega Ring In Pokemon Radical Red
Aspen.sprout Forum
Latest Posts
Article information

Author: Melvina Ondricka

Last Updated:

Views: 6281

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Melvina Ondricka

Birthday: 2000-12-23

Address: Suite 382 139 Shaniqua Locks, Paulaborough, UT 90498

Phone: +636383657021

Job: Dynamic Government Specialist

Hobby: Kite flying, Watching movies, Knitting, Model building, Reading, Wood carving, Paintball

Introduction: My name is Melvina Ondricka, I am a helpful, fancy, friendly, innocent, outstanding, courageous, thoughtful person who loves writing and wants to share my knowledge and understanding with you.