0% found this document useful (0 votes)
4 views4 pages

Basic Letters:: Constants

part 2 notes c language

Uploaded by

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

Basic Letters:: Constants

part 2 notes c language

Uploaded by

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

L2

Language Basics:
Here, you can split your journey of learning C++ language in the following four
steps:

1. Basic Letters
2. Identifiers
3. Instructions
4. Program

1. Basic Letters :
Alphabets A to Za to z
Digits 0 to 9
Special Symbol example: ~ ‘ ! @ # % ^ & * ( ) _ – + = | \ { } [ ] : ; “ ‘ < > , . ?

2. Identifiers:
Combination of letters becomes an identifier. Identifier is the smallest unit in
the program which has some meaning. You are going to learn following
identifiers:

-Constant
-Variables
-Keywords
Constants:
Any Software is developed to handle information. This information is called
constant. Sometimes it is termed as data (raw or processed).
data = information = constant

Constants can be categorized as primary and secondary constants.


Primary Constants:
Primary constants are also known as fundamental constants or basic constants.
They are of three types:

-Integer constant
-Real constant
-Character constant

Integer Constants:
All numbers either positive or negative without decimal point are Integer
Constants.

For example: 35, -20, 0, 123 are valid Integer constant

If the sequence of digits is preceded by 0x or 0X (zero x or zero X), then the


constant is considered to be hexadecimal (base 16). Hexadecimal values may
use the digits from 0 to 9, as well as the letters a to f and A to F.
Few examples: 0x2f, 0X3a2, 0xAB2,
If the first digit is 0 (zero), and the next character is not ‘x’ or ‘X’,
then the constant is considered to be octal (base 8). Octal values may only use
the digits from 0 to 7; 8 and 9 are not allowed. For example: 052, 037

Real Constants:
All numbers either positive or negative with decimal point involved in it are real
constant.
For example: 3.14, -43.56, 3.0 are valid Real constant.

Real constants are also known as floating point literals. A floating-point literal
has an integer part, a decimal point, a fractional part, and an exponent part. You
can represent floating point literals either in decimal form or exponential form.
While representing decimal form, you must include the decimal point, the exponent,
or both; and while representing exponential form, you must include the integer part,
the fractional part, or both. The signed exponent is introduced by e or E.

More examples: 3.14e5, 0.34e-4

Character Constants:

All character symbols are character constants if they are enclosed in single quotes
and of unit length.
For example: ‘A’, ‘b’, ‘+’, ‘3’, ‘ ‘
There are few special characters whose length is two characters but they are treated
as single character, like ‘\n’, ‘\t’, etc.

Secondary Constants:
Secondary constants are also known as derived constants, as they are derived from
primary constants.
Arrays, strings, pointers, structures, union, enumerators are secondary constants.

Variables:
Variables are the names of memory locations where we store our data. When C++
program is under execution, operating system allocates memory to store
instructions of the program and also allocates space to store data.
Programmer has to decide how much space is required to store data. He also
specifies the names of memory locations in his program code. These names are
called variables. These locations can contain integer, real and character constants.
We can change its value according to programming requirement.
Rules for constructing variable name:

1. Variable name may contain alphabets, digits or underscore.


2. No other symbol or blank is allowed.
3. A valid variable name never starts with digit.
Keywords:
Keywords are predefined words. They are also known as reserved words. Their
meaning is known to the compiler.
ANSI (American National Standards Institute) announces 32 keywords in C
language, but it may vary with compilers.
Keywords are predefined and we will see their meaning in subsequent chapters.
Here is the list of keywords:

auto break case char const continue default do


default else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while

ISO C99 adds the following keywords:


inline _Bool _Complex _Imaginary
These keywords cannot be used as variable names or function names as they
already have some meaning known to compiler.

You might also like