Tokens in C | GATE Notes (2024)

Tokens are some of the most important elements used in the C language for creating a program. One can define tokens in C as the smallest individual elements in a program that is meaningful to the functioning of a compiler.

A token is the smallest unit used in a C program. Each and every punctuation and word that you come across in a C program is token. A compiler breaks a C program into tokens and then proceeds ahead to the next stages used in the compilation process.

In this article, we will take a closer look at Tokens in C according to the GATE Syllabus for CSE (Computer Science Engineering). Read ahead to know more.

Table of Contents

  • Tokens In C
  • Use Of The Tokens In C
  • Classification And Types Of Tokens In C
    • Identifiers In C
    • Keywords In C
    • Operators In C
    • Strings In C
    • Special Characters In C
    • Constant In C
  • Practice Problems On Tokens In C
  • FAQs

Use of the Tokens in C

For instance, without words, you cannot create any sentence- similarly, you cannot create any program without using tokens in C language. Thus, we can also say that tokens are the building blocks or the very basic components used in creating any program in the C language.

Classification and Types of Tokens in C

Here are the categories in which we can divide the token in C language:

  • Identifiers in C
  • Keywords in C
  • Operators in C
  • Strings in C
  • Special Characters in C
  • Constant in C

Let’s look at each of these- one by one in detail:

Identifiers in C

These are used to name the arrays, functions, structures, variables, etc. The identifiers are user-defined words in the C language. These can consist of lowercase letters, uppercase letters, digits, or underscores, but the starting letter should always be either an alphabet or an underscore. We cannot make use of identifiers in the form of keywords. Here are the rules that we must follow when constructing the identifiers:

  • The identifiers must not begin with a numerical digit.
  • The first character used in an identifier should be either an underscore or an alphabet. After that, any of the characters, underscores, or digits can follow it.
  • Both- the lowercase and uppercase letters are distinct in an identifier. Thus, we can safely say that an identifier is case-sensitive.
  • We cannot use an identifier for representing the keywords.
  • An identifier does not specify blank spaces or commas.
  • The maximum length of an identifier is 31 characters.
  • We must write identifiers in such a way that it is not only meaningful- but also easy to read and short.

Keywords in C

We can define the keywords as the reserved or pre-defined words that hold their own importance. It means that every keyword has a functionality of its own. Since the keywords are basically predefined words that the compilers use, thus we cannot use them as the names of variables. If we use the keywords in the form of variable names, it would mean that we assign a different meaning to it- something that isn’t allowed. The C language provides a support for 32 keywords, as mentioned below:

autoenumconstgoto
doublecasefloatdefault
structregisterunsignedsizeof
inttypedefshortvolatile
breakexterncontinueif
elsecharfordo
switchreturnvoidstatic
longunionsignedwhile

Operators in C

The operators in C are the special symbols that we use for performing various functions. Operands are those data items on which we apply the operators. We apply the operators in between various operands. On the basis of the total number of operands, here is how we classify the operators:

  • Unary Operator
  • Binary Operator
  • Ternary Operator

Unary Operator

The unary operator in c is a type of operator that gets applied to one single operand, for example: (–) decrement operator, (++) increment operator, (type)*, sizeof, etc.

Binary Operator

Binary operators are the types of operators that we apply between two of the operands. Here is a list of all the binary operators that we have in the C language:

  • Relational Operators
  • Arithmetic Operators
  • Logical Operators
  • Shift Operators
  • Conditional Operators
  • Bitwise Operators
  • Misc Operator
  • Assignment Operator

Ternary Operator

Using this operator would require a total of three operands. For instance, we can use the ?: in place of the if-else conditions.

Strings in C

The strings in C always get represented in the form of an array of characters. We have a ‘\0′ null character at the end of any string- thus, this null character represents the end of that string. In C language, double quotes enclose the strings, while the characters get enclosed typically within various single characters. The number of characters in a string decides the size of that string.

Now, there are different ways in which we can describe a string:

char x[9] = “chocolate’; // Here, the compiler allocates a total of 9 bytes to the ‘x’ array.

char x[] = ‘chocolate’; // Here, the compiler performs allocation of memory during the run time.

char x[9] = {‘c’,’h’,’o’,’c’,’o’,’l’,’a’,’t’,’e’,’\0′}; // Here, we are representing the string in the form of the individual characters that it has.

Special Characters in C

We also use some of the special characters in the C language, and all of them hold a special meaning that we cannot use for any other purpose.

  • () Simple brackets – We use these during function calling as well as during function declaration. For instance, the function printf() is pre-defined.
  • [ ] Square brackets – The closing and opening brackets represent the multidimensional and single subscripts.
  • (,) Comma – We use the comma for separating more than one statement, separating the function parameters used in a function call, and for separating various variables when we print the value of multiple variables using only one printf statement.
  • { } Curly braces – We use it during the closing as well as opening of any code. We also use the curly braces during the closing and opening of the loops.
  • (*) Asterisk – We use this symbol for representing the pointers and we also use this symbol as a type of operator for multiplication.
  • (#) Hash/preprocessor – We use it for the preprocessor directive. This processor basically denotes that the user is utilizing the header file.
  • (.) Period – We use the period symbol for accessing a member of a union or a structure.
  • (~) Tilde – We use this special character in the form of a destructor for free memory.

Constant in C

Constant is basically a value of a variable that does not change throughout a program. The constants remain the same, and we cannot change their value whatsoever. Here are two of the ways in which we can declare a constant:

  • By using a #define pre-processor
  • By using a const keyword

Here is a list of the types of constants that we use in the C language:

Type of ConstantExample
Floating-point constant25.7, 87.4, 13.9, etc.
Integer constant20, 41, 94, etc.
Hexadecimal constant0x5x, 0x3y, 0x8z, etc.
Octal constant033, 099, 077, 011, etc.
String constant“c++”, “.net”, “java”, etc.
Character constant‘p’, ‘q’, ‘r’, etc.

Practice Problems on Tokens in C

1. Which of these is a keyword in the C language?

1. signed

2. register

3. goto

4. enum

A. 1, 2, 4

B. 2, 3

C. 1, 3, 4

D. All of the above

Answer – D. All of the above

2. Identify the rules that must be followed in the case of identifiers:

1. The identifiers must begin with a numerical digit.

2. The first character used in an identifier should be either an underscore or an alphabet.

3. The lowercase and uppercase letters are not distinct in an identifier.

4. An identifier does not specify blank spaces or commas.

5. The maximum length of an identifier is 31 characters.

A. 1, 3, and 5

B. 2, 4, and 5

C. 1, 2, and 4

D. 2, 3, and 5

Answer – B. 2, 4, and 5

3. Which of these is not a constant used in the C language?

A. Octal Constants

B. String Constants

C. Integral Constants

D. Floating Constants

Answer – C. Integral Constants

FAQs

Q1

Is there a difference between constants and literals?

No. Both of these are the same. The syntax of a constant goes as follows:
const data_type variable_name = value;

Q2

Do keywords have functions pre-defined for them, and can we use them for variables?

Yes, keywords have functions pre-defined for them, but we cannot use these to assign names to the variable. If we do so, it would connote a very different meaning, and we will experience a lot of errors.

Keep learning and stay tuned to get the latest updates onGATE Examalong withGATE Eligibility Criteria,GATE 2023,GATE Admit Card,GATE Syllabus for CSE (Computer Science Engineering),GATE CSE Notes,GATE CSE Question Paper, and more.

Also Explore,

  • Constants in C
  • Data Types in C
  • Double Data Type in C
  • Enumerated Data Type in C
  • Operator Precedence and Associativity in C
  • Stacks and Its Applications
  • Static Variable in C
  • Storage Classes in C
Tokens in C | GATE Notes (2024)
Top Articles
Unauthorised, irregular, fruitless and wasteful expenditure
FFP Regulations in Football – Solution or a Complete Scam?
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
Things To Do In Atlanta Tomorrow Night
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Dmv In Anoka
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Rogold Extension
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Weekly Math Review Q4 3
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Fredrick Kertzmann

Last Updated:

Views: 6321

Rating: 4.6 / 5 (46 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Fredrick Kertzmann

Birthday: 2000-04-29

Address: Apt. 203 613 Huels Gateway, Ralphtown, LA 40204

Phone: +2135150832870

Job: Regional Design Producer

Hobby: Nordic skating, Lacemaking, Mountain biking, Rowing, Gardening, Water sports, role-playing games

Introduction: My name is Fredrick Kertzmann, I am a gleaming, encouraging, inexpensive, thankful, tender, quaint, precious person who loves writing and wants to share my knowledge and understanding with you.