0% found this document useful (0 votes)
17 views16 pages

Tokens

tokens in c

Uploaded by

punny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views16 pages

Tokens

tokens in c

Uploaded by

punny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Tokens

 A token is the smallest element of a program that is meaningful


to the compiler.
 we cannot create a program in C without using tokens in C.
Therefore, we can say that tokens in C is the building block or the
basic component for creating a program in C language.
 Tokens can be classified as follows:
• Keywords
• Identifiers
• Constants
• Strings
• Special Symbols
• Operators
Keywords
• Keywords are pre-defined or reserved words
in a programming language. Each keyword is
meant to perform a specific function in a
program.
• Since keywords are referred names for a
compiler, they can’t be used as variable names
because by doing so, we are trying to assign a
new meaning to the keyword which is not
allowed.
C language supports 32 keywords :
Identifiers in C
• Identifiers in C are used for naming variables,
functions, arrays, structures, etc. Identifiers in
C are the user-defined words.
• It can be composed of uppercase letters,
lowercase letters, underscore, or digits, but
the starting letter should be either an
underscore or an alphabet.
Rules
• The first character of an identifier should be either an alphabet
or an underscore, and then it can be followed by any of the
character, digit, or underscore.
• It should not begin with any numerical digit.
• In identifiers, both uppercase and lowercase letters are distinct.
Therefore, we can say that identifiers are case sensitive.
• Commas or blank spaces cannot be specified within an identifier.
• Keywords cannot be represented as an identifier.
• The length of the identifiers should not be more than 31
characters.
• Identifiers should be written in such a way that it is meaningful,
short, and easy to read.
Example
• sumNumbers();
• Sum
• num1
Strings in C

• Strings in C are always represented as an array


of characters having null character '\0' at the
end of the string.
• This null character denotes the end of the
string.
• Strings in C are enclosed within double quotes,
while characters are enclosed within single
characters.
• char a[10] = “program1234"
Operators in C
• Operators are used to perform operations on
variables and values.
• operators as symbols that help us to perform
specific mathematical and logical
computations on operands
• c = a + b;
• ‘+’ is the operator known as the addition
operator and ‘a’ and ‘b’ are operands. Thus an
operator operates the operands
• The data items on which the operators are
applied are known as operands.
• Operators are applied between the operands.
Depending on the number of operands,
operators are classified as follows:
Constants in C

• A constant is a value assigned to the variable


which will remain the same throughout the
program, i.e., the constant value cannot be
changed.
• There are two ways of declaring constant:
• Using const keyword
• Using #define pre-processor
Special characters in C

• Some special characters are used in C, and they have a


special meaning which cannot be used for another
purpose.
• Square brackets [ ]: The opening and closing brackets
represent the single and multidimensional subscripts.
• Simple brackets ( ): It is used in function declaration and
function calling. For example, printf() is a pre-defined
function.
• Curly braces { }: It is used in the opening and closing of
the code. It is used in the opening and closing of the
loops.
• Comma (,): It is used for separating for more than one
statement and for example, separating function parameters in
a function call, separating the variable when printing the value
of more than one variable using a single printf statement.
• Hash/pre-processor (#): It is used for pre-processor directive.
It basically denotes that we are using the header file.
• Asterisk (*): This symbol is used to represent pointers and also
used as an operator for multiplication.
• Tilde (~): It is used as a destructor to free memory.
• Period (.): It is used to access a member of a structure or a
union.
Semicolons

• In a C program, the semicolon is a statement


terminator. That is, each individual statement
must be ended with a semicolon.
• Example−
• printf("Hello, World! \n");
• return 0;
Comments

• Comments are like helping text in your C


program and they are ignored by the compiler.
They start with /* and terminate with the
characters */ as shown below −
• /* my first program in C */

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy