Tokens in C
Tokens in C
Tokens are called building block of C programming, that means only with the help of tokens a C program can be created. Every small part that is used in the program is called tokens. In C programming, some INDIVIDUAL words and characters are fixed, whose functions are fixed, called tokens. It is the smallest element of C program. There are some internal tokens we need to know while writing a program in C to understand the most basic to the syntax of the C language.
Tokens in C
Tokens are called building block of C programming, that means only with the help of tokens a C program can be created.
- every small part that is used in the program is called tokens.
- In C programming, some INDIVIDUAL words and characters are fixed, whose functions are fixed, called tokens.
- It is the smallest Lexial unit of C program.
There are some internal tokens we need to know while writing a program in C to understand the most basic to the syntax of the C language.
Some internal tokens are:-
- Keywords
- Identifiers
- Constants
- Strings
- Special Symbols
- Operators
for example, look at the program below. this program is used in the correct order of tokens.
#include
int main()
{
printf("my name is somya");
printf("%d",4);
}
KEYWORDS
Keywords are predefined statements ,operators reserved words which have a special meaning to the compiler while execution, they are a part of it and can not be used as an identifier. C language provides 32 keywords. every keyword has a special meaning. each keyword is defined to do a specific job. Here is a list of some identifiers given belowauto | else | long | switch |
break | enum | register | typedef |
case | double | return | union |
char | float | short | unsigned |
const | for | signed | void |
continue | goto | sizeof | volatile |
default | if | static | while |
do | int | struct | _Packed |
IDENTIFIERS
In a simple language an identifier is the name of a variable (integer,float(decimal),character) given to a variable or constant for a program just like a math problem. It can start anywhere from A to Z or a to z or underscore ( _ ) and you may or may not add more to the later by integer digits or more letters or underscores . But one should always remember that C is a case-sensitive programming language .So identifiers like Goku, goku, _goku, goku1 ,Goku1 are all different identifiers . Note : C doesn’t allow punctuation’s like ! @ $ % & * in identifiers so make sure you don’t have a g@ku or goku! named identifier . Identifiers are the names that give you variables,constants and functions. these are some rules to give to these names that you follow, if you don’t follow then there is an error in the program.- In Identifiers @, %, -characters can not be used.
- C is a Case sensitive language, So more and More both are said to be different identifiers.
- In Identifiers, we can not use operators.
- It can start anywhere from A to Z or a to z or underscore ( _ ) and you may or may not add more to the later by integer digits or more letters or underscores.
- you can either start an identifier with either a character or underscore. Digits can not be started from identifiers.
Example:-
_old //identifier 2name //not identifier person-name //not identifier person_2_old //identifier.
CONSTANTS
Constant is a value, which does not change in program execution.- constant value is fixed.
- it is also known as Literals.
- it does not matter where we use it in program,its meaning always fixed.
- it is also like normal variables.
Types of Constants:-
1.Integer constant -The whole values used in the C program are called integer constant. Like: 1,53,677 e.t.c. 2.Character constant – The different characters used in the C program are called character constant. Like: f, v, s, w, # e.t.c. 3.Float constant – In C program, such numeric value in which the digit after the decimal is called float constant. Like: 4.44444, 34.6634 etc. 4.String constant – many literal characters are placed under string literal. Like: “rat”, “prep”,etc.STRINGS
The group of characters is known as strings. which are always enclosed in double quote. it is also said to be array of characters.it is used to stored data of class,mobile numbers , name etc. At the end of the string there is always a special character, which is known as null. its indicate the end of the string.Declaration of Strings:-
char string[20] = {‘p’,’r’,’e’,’p’,’I’,’n’,’s’,’t’,’a’,’\0′}; char string[20] = “prepInsta”; char string[] = “prepInsta”;SPECIAL SYMBOL:-
Some special symbols are used in C programming. symbols means alphabet, exclude the digits using some symbols in C programming.In C programming some special symbol are used in C having some special meaning and cannot be use in other purpose. The following symbols are:- Braces {}:- these curly braces are used to show the starting and ending of a block of code containing some executable statement. Parentheses ():- Parentheses are used to specify the function call and function parameter. Brackets []:- this is the opening and closing brackets. it is used as array element reference. these stipulate the single and multidimensional subscripts. Comma (,) :- it is used to separate more then one statement. Asterick (*) :- used to create pointer variable. Assignment variable:- used to assign values. Semicolon:- In C program after every statement we have to put a semicolon (;) which tells the compiler the statement ends there .For exampleprintf("Kamehameha"); return 6;It indicates the end of one logical entity.
OPERATORS
Operators is special symbol which is used to perform mathematical operation like, addition, subtraction, division, multiplication.Different types of symbols are used to perform different type of mathematical and logical operation in C programming is known as operators. that symbols.types of operator:-
- Unary Operator:– unary operators are those operators, which require only single operands is known as unary operator.
- Arithmetic operator
- Logical operator
- Bitwise operator
- Conditional operator
- Relational operator
- Assignment operator
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Easy to understand
good concepts
Thank you for your appreciation and also we want you to know that we are more than happy to help you and serve you better!!!
Great
Thanks for the appreciation Prakash
Hello ! In the identifiers and keywords section given that keywords start with lower case letters and it contains only lower case letters . But _Packed keyword given in the list does not matches . can you please clear my dought . Thankyou
It is basically not a keyword but a qualifier, which is used to remove padding between members of structures or unions.