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
Payment Request Letter Template - [Format & Sample]
How to Professionally Ask for Payment + Free Templates – Helm
Funny Roblox Id Codes 2023
San Angelo, Texas: eine Oase für Kunstliebhaber
Golden Abyss - Chapter 5 - Lunar_Angel
Www.paystubportal.com/7-11 Login
Evil Dead Rise Showtimes Near Massena Movieplex
Steamy Afternoon With Handsome Fernando
fltimes.com | Finger Lakes Times
Detroit Lions 50 50
18443168434
Newgate Honda
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
Grace Caroline Deepfake
978-0137606801
Nwi Arrests Lake County
Missed Connections Dayton Ohio
Justified Official Series Trailer
London Ups Store
Committees Of Correspondence | Encyclopedia.com
Jinx Chapter 24: Release Date, Spoilers & Where To Read - OtakuKart
How Much You Should Be Tipping For Beauty Services - American Beauty Institute
Apply for a credit card
VERHUURD: Barentszstraat 12 in 'S-Gravenhage 2518 XG: Woonhuis.
Unforeseen Drama: The Tower of Terror’s Mysterious Closure at Walt Disney World
Ups Print Store Near Me
How Taraswrld Leaks Exposed the Dark Side of TikTok Fame
University Of Michigan Paging System
Dashboard Unt
Access a Shared Resource | Computing for Arts + Sciences
2023 Ford Bronco Raptor for sale - Dallas, TX - craigslist
Speechwire Login
Healthy Kaiserpermanente Org Sign On
Restored Republic
Progressbook Newark
Lawrence Ks Police Scanner
3473372961
Landing Page Winn Dixie
Everstart Jump Starter Manual Pdf
Hypixel Skyblock Dyes
Senior Houses For Sale Near Me
Flashscore.com Live Football Scores Livescore
Ktbs Payroll Login
Jail View Sumter
Thotsbook Com
Funkin' on the Heights
Caesars Rewards Loyalty Program Review [Previously Total Rewards]
Marcel Boom X
Www Pig11 Net
Ty Glass Sentenced
Game Akin To Bingo Nyt
Latest Posts
Article information

Author: Arielle Torp

Last Updated:

Views: 6064

Rating: 4 / 5 (41 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.