Tokens in C - GeeksforGeeks

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

C C Basics C Data Types C Operators C Input and Output C Control Flow C Functions C Arrays CS

Tokens in C
A token in C can be defined as the smallest individual element of the C
programming language that is meaningful to the compiler. It is the basic
component of a C program.

Types of Tokens in C
The tokens of C language can be classified into six types based on the
functions they are used to perform. The types of C tokens are as follows:

1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special Symbols
6. Operators

1. C Token – Keywords
The keywords are pre-defined or reserved words in a programming
language. Each keyword is meant to perform a specific function in a
We useprogram. Sinceyoukeywords
cookies to ensure have the bestare referred
browsing names
experience on ourfor a compiler,
website. By using they can’t be
our site,
usedyou acknowledge
as variable thatnames
you havebecause
read and understood
by doing our Cookie
so, we Policy Privacy to assignGot
are& trying a Itnew
!
Policy
meaning to the keyword which is not allowed. You cannot redefine
keywords. However, you can specify the text to be substituted for keywords
before compilation by using C preprocessor directives. C language supports
32 keywords which are given below:

auto double int struct


break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

2. C Token – Identifiers
Identifiers are used as the general terminology for the naming of variables,
functions, and arrays. These are user-defined names consisting of an
arbitrarily long sequence of letters and digits with either a letter or the
underscore(_) as a first character. Identifier names must differ in spelling and
case from any keywords. You cannot use keywords as identifiers; they are
reserved for special use. Once declared, you can use the identifier in later
program statements to refer to the associated value. A special identifier
called a statement label can be used in goto statements.

THIS Will Make You RICH! | Make Money Si…

We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
06:10

Rules for Naming Identifiers

Certain rules should be followed while naming c identifiers which are as


follows:

They must begin with a letter or underscore(_).


They must consist of only letters, digits, or underscore. No other special
character is allowed.
It should not be a keyword.
It must not contain white space.
It should be up to 31 characters long as only the first 31 characters are
significant.

Note: Identifiers are case-sensitive so names like variable and Variable


will be treated as different.

For example,

main: method name.


a: variable name.

3. C Token – Constants
The constants refer to the variables with fixed values. They are like normal
variables but with the difference that their values can not be modified in the
program once they are defined.

Constants may belong to any of the data types.

Examples of Constants in C

We use const
cookies toint
ensurec_var
you have=the20;
best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
const int* const ptr = &c_var;
Policy
4. C Token – Strings
Strings are nothing but an array of characters ended with a null character
(‘\0’). This null character indicates the end of the string. Strings are always
enclosed in double quotes. Whereas, a character is enclosed in single quotes
in C and C++.

Examples of String

char string[20] = {‘g’, ’e’, ‘e’, ‘k’, ‘s’, ‘f’, ‘o’, ‘r’, ‘g’,
’e’, ‘e’, ‘k’, ‘s’, ‘\0’};
char string[20] = “geeksforgeeks”;
char string [] = “geeksforgeeks”;

5. C Token – Special Symbols


The following special symbols are used in C having some special meaning
and thus, cannot be used for some other purpose. Some of these are listed
below:

Brackets[]: Opening and closing brackets are used as array element


references. These indicate single and multidimensional subscripts.
Parentheses(): These special symbols are used to indicate function calls
and function parameters.
Braces{}: These opening and ending curly braces mark the start and end
of a block of code containing more than one executable statement.
Comma (, ): It is used to separate more than one statement like for
separating parameters in function calls.
Colon(:): It is an operator that essentially invokes something called an
initialization list.
Semicolon(;): It is known as a statement terminator. It indicates the end
of one logical entity. That’s why each individual statement must be ended
with a semicolon.
Asterisk (*): It is used to create a pointer variable and for the
multiplication of variables.
Assignment operator(=): It is used to assign values and for logical
operation validation.
Pre-processor
We use cookies (#):theThe
to ensure you have preprocessor
best browsing experienceisonaour
macro
website.processor
By using that is used
automatically
our site, you acknowledge thatbyyouthe
havecompiler to transform
read and understood our Cookieyour
Policyprogram
& Privacy before actual
compilation. Policy
Period (.): Used to access members of a structure or union.
Tilde(~): Used as a destructor to free some space from memory.

6. C Token – Operators
Operators are symbols that trigger an action when applied to C variables
and other objects. The data items on which operators act are called
operands.
Depending on the number of operands that an operator can act upon,
operators can be classified as follows:

Unary Operators: Those operators that require only a single operand to


act upon are known as unary operators.For Example increment and
decrement operators
Binary Operators: Those operators that require two operands to act upon
are called binary operators. Binary operators can further are classified
into:
1. Arithmetic operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Bitwise Operator

Ternary Operator: The operator that requires three operands to act upon
is called the ternary operator. Conditional Operator(?) is also called the
ternary operator.

This article is contributed by I.HARISH KUMAR.

Here's a complete roadmap for you to become a developer: Learn DSA ->
Master Frontend/Backend/Full Stack -> Build Projects -> Keep Applying
to Jobs And why go anywhere else when our DSA to Development: Coding
Guide helps you do this in a single program!
Apply now to our DSA to Development Program and our counsellors will
connect with you for further guidance & support.

Maximize your earnings for your published articles in Dev Scripter 2024! Showcase
We use cookies to ensure you have the best browsing experience on our website. By using
expertise,
our site, gain recognition
you acknowledge & get
that you have read andextra compensation
understood while
our Cookie Policy elevating your tech
& Privacy
profile. Policy
Last Updated : 03 Jul, 2023 445

Previous Next

C Comments Keywords in C

Share your thoughts in the comments Add Your Comment

Similar Reads
C program to detect tokens in a C
program

I I.HARISH KUMAR

Article Tags : C Basics , C Language

A-143, 9th Floor, Sovereign Corporate


Tower, Sector-136, Noida, Uttar Pradesh -
201305

We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy
Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Careers GfG Weekly Contest
In Media Offline Classes (Delhi/NCR)
Contact Us DSA in JAVA/C++
Advertise with us Master System Design
GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Geeks Community

Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL DSA Interview Questions
R Language Competitive Programming
Android Tutorial

Data Science & ML Web Technologies


Data Science With Python HTML
Data Science For Beginner CSS
Machine Learning Tutorial JavaScript
ML Maths TypeScript
Data Visualisation Tutorial ReactJS
Pandas Tutorial NextJS
NumPy Tutorial NodeJs
NLP Tutorial Bootstrap
Deep Learning Tutorial Tailwind CSS

Python Tutorial Computer Science


We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have
Python Programming read and understood our Cookie Policy & Privacy
Examples GATE CS Notes
Policy
Django Tutorial Operating Systems
Python Projects Computer Network
Python Tkinter Database Management System
Web Scraping Software Engineering
OpenCV Tutorial Digital Logic Design
Python Interview Question Engineering Maths

DevOps System Design


Git High Level Design
AWS Low Level Design
Docker UML Diagrams
Kubernetes Interview Guide
Azure Design Patterns
GCP OOAD
DevOps Roadmap System Design Bootcamp
Interview Questions

School Subjects Commerce


Mathematics Accountancy
Physics Business Studies
Chemistry Economics
Biology Management
Social Science HR Management
English Grammar Finance
Income Tax

UPSC Study Material Preparation Corner


Polity Notes Company-Wise Recruitment Process
Geography Notes Resume Templates
History Notes Aptitude Preparation
Science and Technology Notes Puzzles
Economy Notes Company-Wise Preparation
Ethics Notes Companies
Previous Year Papers Colleges

Competitive Exams More Tutorials


We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge
JEEthat you have read and understood our Cookie Policy & Software
Advanced Privacy Development
Policy
UGC NET Software Testing
SSC CGL Product Management
SBI PO Project Management
SBI Clerk Linux
IBPS PO Excel
IBPS Clerk All Cheat Sheets

Free Online Tools Write & Earn


Typing Test Write an Article
Image Editor Improve an Article
Code Formatters Pick Topics to Write
Code Converters Share your Experiences
Currency Converter Internships
Random Number Generator
Random Password Generator

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

We use cookies to ensure you have the best browsing experience on our website. By using
our site, you acknowledge that you have read and understood our Cookie Policy & Privacy
Policy

You might also like