(Lect. 4) Token Variable Constant
(Lect. 4) Token Variable Constant
UNIT-II
C Tokens
The smallest element in the C language is the token.
It may be a single character or a sequence of characters.
C Tokens
int xval;
const int service_tax = 0.12;
const float pi = 3.14;
void sum_of_num( );
The rules for forming identifier
First character must be alphabetic or
underscore.
Must consist only of alphabetic characters,
digits, or underscores.
Only the first 31 characters of an identifier are
significant and are recognized by the compiler.
Cannot use a keywords or reserved word (e.g.
main, include, printf & scanf etc.).
No space are allowed between the identifiers
etc,.
C is case sensitive, e.g. My_name
my_name.
Variables
• A variable is a container (storage area) to hold data.
• Each variable should be given a unique name (identifier).
• Variable names are just the symbolic representation of a
memory location.
• A variable name can be chosen by you.
• The C language allows storing different types of data into the
variables & proper declaration for the variable is made before
it is used in the program.
• Variables can be used to store floating-point numbers,
characters, and even pointers to memory locations.
Variables
• Is a memory location
• Have a name given by the programmer
• It can store/hold a value
• Its value can be changed/altered/modified
• Every variable belongs to a data type
Constants
Real constants
It is formed using a sequence of digits but it contain decimal
point.
length, height, price distance measured in real number
Eg: 2.5, 5.11, etc.
Character constants
Single character constant
A character constant is a single character they also
represented with single digit or a single special
symbol which is enclosed in single quotes.
Eg: ‘a’, ‘8’,’_’etc.
String constants
String constant are sequence of characters enclosed with in
double quote.
Eg: “Hello” ,”444”,”a” etc,.
main() {
int x;
x=5.5;
printf(“%d”, x);
x=6;
printf(“%d”, x);
}
ASCII Code
ASCII stands for American Standard Code for Information
Interchange.
In C programming, a character variable holds ASCII value
rather than that character itself. This integer value is the ASCII
code of the character.
For example, the ASCII value of 'A' is 65.
char ch=’A’;
What this means is that, if you assign 'A' to a character
variable, 65 is stored in the variable rather than 'A' itself.
Program to Print ASCII Value
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
return 0;