
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Tokens in C
Tokens are the smallest elements of a program, which are meaningful to the compiler.
The following are the types of tokens: Keywords, Identifiers, Constant, Strings, Operators, etc.
Let us begin with Keywords.
Keywords
Keywords are predefined, reserved words in C and each of which is associated with specific features. These words help us to use the functionality of C language. They have special meaning to the compilers.
There are total 32 keywords in C.
auto | double | int | struct |
break | else | long | switch |
case | enum | register | typedef |
char | extern | return | union |
continue | for | signed | void |
do | if | static | while |
default | goto | sizeof | volatile |
const | float | short | unsigned |
Identifiers
Each program element in C programming is known as an identifier. They are used for naming of variables, functions, array etc. These are user-defined names which consist of alphabets, number, underscore ‘_’. Identifier’s name should not be same or same as keywords. Keywords are not used as identifiers.
Rules for naming C identifiers −
It must begin with alphabets or underscore.
Only alphabets, numbers, underscore can be used, no other special characters, punctuations are allowed.
It must not contain white-space.
It should not be a keyword.
It should be up to 31 characters long.
Strings
A string is an array of characters ended with a null character(\0). This null character indicates that string has ended. Strings are always enclosed with double quotes(“ “).
Let us see how to declare String in C language −
- char string[20] = {‘s’,’t’,’u’,’d’,’y’, ‘\0’};
- char string[20] = “demo”;
- char string [] = “demo”;
Here is an example of tokens in C language,
Example
#include >stdio.h> int main() { // using keyword char char a1 = 'H'; int b = 8; float d = 5.6; // declaration of string char string[200] = "demodotcom"; if(b<10) printf("Character Value : %c
",a1); else printf("Float value : %f
",d); printf("String Value : %s
", string); return 0; }
Output
Character Value : H String Value : demodotcom
- Related Articles
- C/C++ Tokens?
- Explain C tokens in C Language
- Bag of Tokens in C++
- What are tokens in C#?
- What are the tokens in C ?
- What are the C Tokens?
- Tokens vs Identifiers vs Keywords in C++
- C program to detect tokens in a C program
- C program to print string tokens
- What do you mean by C++ Tokens?
- What are tokens in Java?
- Substitute tokens in a String in Java
- Crypto Primer: Currencies, Commodities and Tokens
- Crypto Tokens: Everything you need to know
- How to add Tokens to the test network Metamask?
