0% found this document useful (0 votes)
77 views26 pages

Indentifiers, Keywords, Constants

1. C uses letters, digits, and certain special characters as building blocks for program elements. Identifiers are names given to program elements and consist of letters, digits, and underscores, but must start with a letter. 2. There are different data types in C including integer, floating point, character, and string. Each data type represents data in memory in a specific way and has a different range of possible values. 3. Constants in C include integer, floating point, character, and string constants. Integer constants can be written in decimal, octal, or hexadecimal and have certain formatting rules and value ranges depending on their type.
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)
77 views26 pages

Indentifiers, Keywords, Constants

1. C uses letters, digits, and certain special characters as building blocks for program elements. Identifiers are names given to program elements and consist of letters, digits, and underscores, but must start with a letter. 2. There are different data types in C including integer, floating point, character, and string. Each data type represents data in memory in a specific way and has a different range of possible values. 3. Constants in C include integer, floating point, character, and string constants. Integer constants can be written in decimal, octal, or hexadecimal and have certain formatting rules and value ranges depending on their type.
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/ 26

Identifiers, Keywords, Constants

Date:19.09.23
THE C CHARACTER SET
• C uses the uppercase letters A to Z, the lowercase letters a to z, the digits 0 to 9, and certain special
characters as building blocks to form basic program elements (e.g., constants, variables, operators,
expressions, etc.).
• The special characters are listed below.

• Most versions of the language also allow certain other characters, such as @ and $, to be included
within strings and comments.
• C uses certain combinations of these characters, such as \b, \n and \t,to represent special conditions
such as backspace, newline and horizontal tab, respectively. These character combinations are
known as escape sequences.
IDENTIFIERS AND KEYWORDS
• Identifiers are names that are given to various program elements, such as variables, functions and arrays.
• Identifiers consist of letters and digits, in any order, except that the first character must be a letter.
• Both upper- and lowercase letters are permitted, though common usage favors the use of lowercase letters for most types of
identifiers.
• Upper- and lowercase letters are not interchangeable (i.e., an uppercase letter is not equivalent to the corresponding lowercase
letter.)
• The underscore character (_) can also be included and is considered to be a letter.
• An underscore is often used in the middle of an identifier. An identifier may also begin with an underscore.
• Example:
• Valid Identifiers:
X Y12 sum_1 _temperature
• Invalid Identifiers:
4th The first character must be a letter.
"x" Illegal characters (“).
order-no Illegal character (-).
error flag Illegal character (blank space).
IDENTIFIERS AND KEYWORDS
• An identifier can be arbitrarily long. Some implementations of C recognize only
the first eight characters, though most implementations recognize more (typically,
31 characters).
• Example: The identifiers file-manager and file-management
• As a rule, an identifier should contain enough characters so that its meaning is
readily apparent. On the other hand, an excessive number of characters should be
avoided.
• There are certain reserved words, called keywords, that have standard, predefined
meanings in C.
• These keywords can be used only for their intended purpose; they cannot be used
as programmer-defined identifiers.
IDENTIFIERS AND KEYWORDS
• The standard keywords are

• Some compilers may also include some or all of the following keywords.
Bit,Byte,Nibble,word
1.Bit (Binary Digit):
•A bit is the smallest unit of data in computing and digital communications.
•It can have a value of either 0 or 1, representing off or on, respectively.
•The term "bit" is a contraction of "binary digit."
2.Byte:
•A byte consists of 8 bits.
•It is a fundamental unit of data storage and processing in computing.
•Bytes are used to represent characters (e.g., letters, numbers, symbols) and are the basis for addressing and storing data in memory.
3.Nibble:
•A nibble is half of a byte, containing 4 bits.
•Nibbles are used in computing operations where it's useful to work with small units of data.
4.Word:
•The size of a word can vary depending on the computer architecture and the specific system, but it's typically the natural unit of data a
CPU can process at one time (e.g., 16 bits, 32 bits, 64 bits).
•A word's size is an essential characteristic of a computer's architecture, affecting memory addressing and processing capabilities.

•A bit is the smallest unit, representing a binary value (0 or 1).


•A byte consists of 8 bits and is a fundamental unit of data.
•A nibble is half a byte, containing 4 bits.
•A word is a unit of data processing, and its size can vary based on the computer architecture.
To illustrate:
•1 byte = 8 bits
•1 nibble = 4 bits (half a byte)
•The size of a word can vary, such as 16 bits (2 bytes), 32 bits (4 bytes), or 64 bits (8 bytes), depending on the system architecture.
DATA TYPES
• C supports several different types of data, each of which may be represented
differently within the computer’s memory.
• The memory requirements for each data type will determine the permissible range
of values for that data type.
• Note that the memory requirements for each data type may vary from one C
compiler to another.
DATA TYPES
• C compilers written for personal computers or small minicomputers (i.e., computers
whose natural word size is less than 32 bits) generally represent a word as 4 bytes (32
bits)
• The basic data types can be augmented by the use of the data type qualifiers short, long,
signed and unsigned.
• For example, integer quantities can be defined as short int, long int or unsigned int (these
data types are usually written simply as short, long or unsigned, and are understood to be
integers).
• If short int and int both have the same memory requirements (e.g., 2 bytes), then long int
will generally have double the requirements (e.g., 4 bytes). Or if int and long int both
have the same memory requiremements (e.g., 4 bytes) then short int will generally have
half the memory requirements (e.g., 2 bytes). Remember that the specifics will vary from
one C compiler to another.
DATA TYPES
• An unsigned int has the same memory requirements as an ordinary int. However, in the case of an ordinary int
(or a short int or a long int), the leftmost bit is reserved for the sign. With an unsigned int, all of the bits are
used to represent the numerical value. Thus, an unsigned int can be approximately twice as large as an ordinary
int.
• For example, if an ordinary int can vary from -32,768 to +32,767 (which is typical for a 2-byte int), then an
unsigned int will be allowed to vary from 0 to 65,535.
• The unsigned qualifier can also be applied to other qualified ints, e.g., unsigned short int or unsigned long int.
• The char type is used to represent individual characters. Hence, the char type will generally require only one
byte of memory.
• Each char type has an equivalent integer interpretation, however, so that a char is a really a special kind of short
integer.
• With most compilers, a char data type will permit a range of values extending from 0 to 255.
• Some compilers represent the char data type as having a range of values extending from -128 to +127.
• There may also be unsigned char data (with typical values ranging from 0 to 255), or signed char data (with
values ranging from -128 to +127).
DATA TYPES
• Some compilers permit the qualifier long to be applied to float or to
double, e.g., long float, or long double.
• Thus, long float may be equivalent to double. Moreover, long double
may be equivalent to double, or it may refer to a separate, “extra-
large” double-precision data type requiring more than two words of
memory.
• Two additional data types, void and enum(…read about this)
• Every identifier that represents a number or a character within a C
program must be associated with one of the basic data types before the
identifier appears in an executable statement - type declaration.
CONSTANTS
• Four basic types of constants in C. They are integer constants, floating-point
constants, character constants and string constants (there are also
enumeration constants)
• Integer and floating-point constants represent numbers. They are often referred
to collectively as numeric-type constants.
• The following rules apply to all numeric-type constants:
• Commas and blank spaces cannot be included within the constant.
• The constant can be preceded by a minus (-) sign if desired. (Actually the minus sign is
an operator that changes the sign of a positive constant, though it can be thought of as a
part of the constant itself.)
• The value of a constant cannot exceed specified minimum and maximum bounds. For
each type of constant, these bounds will vary from one C compiler to another.
CONSTANTS
• Integer Constants:
• An integer constant is an integer-valued number.
• Thus it consists of a sequence of digits.
• Integer constants can be written in three different number systems: decimal (base 10), octal (base 8) and
hexadecimal (base 16).
• A decimal integer constant can consist of any combination of digits taken from the set 0 through 9. If the
constant contains two or more digits, the first digit must be something other than 0.
• Example:
• Valid decimal integer constants:
• 0 1 743 5280 32767 9999
• Invalid decimal integer constants:
CONSTANTS
• An octal integer constant can consist of any combination of digits
taken from the set 0 through 7. However the first digit must be 0,in
order to identify the constant as an octal number.
• Example:
• Valid octal constants:
• 0 01 0743 077777
• Invalid octal constants:
CONSTANTS
• A hexadecimal integer constant must begin with either 0x or 0X.
• It can then be followed by any combination of digits taken from the sets 0 through
9 and a through f (either upper- or lowercase).
• Note that the letters a through f (or A through F) represent the (decimal) quantities
10 through 15, respectively.
• Example:
• Valid hexadecimal constants:
• 0x 0x 1 0X7FFF 0xabcd
• Invalid hexadecimal constants:
CONSTANTS
• The magnitude of an integer constant can range from zero to some
maximum value that varies from one computer to another (and from
one compiler to another, on the same computer).
• A typical maximum value for most personal computers and many
minicomputers is 32767 decimal (equivalent to 77777 octal or 7fff
hexadecimal), which is 215-1.
• Mainframe computers generally permit larger values, such as
2,147,483,647 (which is 231- 1).
CONSTANTS
• Unsigned and Long Integer Constants
• Unsigned integer constants may exceed the magnitude of ordinary integer constants by
approximately a factor of 2, though they may not be negative.
• An unsigned integer constant can be identified by appending the letter U (either upper- or
lowercase) to the end of the constant.
• Long integer constants may exceed the magnitude of ordinary integer constants but require
more memory within the computer.
• With some computers (and/ or some compilers), a long integer constant will automatically be
generated simply by specifying a quantity that exceeds the normal maximum value.
• It is always possible, however, to create a long integer constant by appending the letter L
(either upper- or lowercase) to the end of the constant.
• An unsigned long integer may be specified by appending the letters UL to the end of the
constant. The letters may be written in either upper- or lowercase. However, the U must
precede the L.
CONSTANTS
• Examples: unsigned and long integer constants

• The maximum permissible values of unsigned and long integer constants will vary from one computer (and
one compiler) to another. With some computers, the maximum permissible value of a long integer constant
may be the same as that for an ordinary integer constant; other computers may allow a long integer constant
to be much larger than an ordinary integer constant.
• Note:
• Suppose a particular computer uses a w-bit word. Then an ordinary integer quantity may fall within the range -2w – 1
to +2w - 1, whereas an unsigned integer quantity may vary from 0 to 2w - 1. A short integer may substitute w/2 for w,
and a long integer may substitute 2w for w. These rules may vary from one computer to another.
CONSTANTS
• Floating-Point Constants
• is a base- 10 number that contains either a decimal point or an exponent (or
both).
• Example: Valid Floating-Point Constants

• Invalid Floating-Point Constants


CONSTANTS
• If an exponent is present, its effect is to shift the location of the
decimal point to the right, if the exponent is positive, or to the left, if
the exponent is negative.
• If a decimal point is not included within the number, it is assumed to
be positioned to the right of the last digit.
• The interpretation of a floating-point constant with an exponent is
essentially the same as scientific notation, except that the base 10 is
replaced by the letter E (or e). Thus, the number 1.2 x 10-3 would be
written as 1 .2E-3 or 1 .2e-3. This is equivalent to 0.12e-2, or 12e-4,
etc.
CONSTANTS
• The quantity 5.026 x 10-l7 can be represented by any of the following
floating-point constants.

• Floating-point constants have a much greater range than integer constants.


Typically, the magnitude of a floating-point constant might range from a
minimum value of approximately 3.4E-38 to a maximum of 3.4E+38.
• Some versions of the language permit floating-point constants that cover a
wider range, such as 1 .7E-308 to 1 .7E+308.
• Also, the value 0.0 (which is less than either 3.4E-38 or 1 .7E-308) is a
valid floating-point constant.
CONSTANTS
• Floating-point constants are normally represented as double-precision quantities in C.
• Hence, each floating-point constant will typically occupy 2 words (8 bytes) of memory.
• Some versions of C permit the specification of a “single-precision,” floating-point
constant, by appending the letter F (in either upper- or lowercase) to the end of the
constant (e.g., 3E5F).
• Similarly, some versions of C permit the specification of a “long” floating-point
constant, by appending the letter L (upper- or lowercase) to the end of the constant
(e.g., 0.123456789E-33L).
• The precision of floating-point constants (i.e., the number of significant figures) will
vary from one version of C to another. Virtually all versions of the language permit at
least six significant figures, and some versions permit as many as eighteen significant
figures.
Character constants
• A "character constant" is formed by enclosing a single character from
the representable character set within single quotation marks (' ‘).
Ascii Character set
Escape sequence
The escape sequence in C is the characters or the sequence of characters that can be used inside the string literal.
The purpose of the escape sequence is to represent the characters that cannot be used normally using the keyboard.
Some escape sequence characters are the part of ASCII charset but some are not.

You might also like