0% found this document useful (0 votes)
39 views

Constant Variables and Data Types

The document discusses various aspects of C programming including: 1. C constants include primary constants like integers and real numbers, and secondary constants like arrays and structures. Constants cannot change during program execution. 2. Variables are used to store constants in memory locations and must be of the same type as the stored constant. Variable names can be up to 8 characters with an alphabet as the first character. 3. C has 32 reserved keywords that cannot be used as variable names like if, else, int, float, etc.

Uploaded by

dixitjitekchand
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Constant Variables and Data Types

The document discusses various aspects of C programming including: 1. C constants include primary constants like integers and real numbers, and secondary constants like arrays and structures. Constants cannot change during program execution. 2. Variables are used to store constants in memory locations and must be of the same type as the stored constant. Variable names can be up to 8 characters with an alphabet as the first character. 3. C has 32 reserved keywords that cannot be used as variable names like if, else, int, float, etc.

Uploaded by

dixitjitekchand
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

Constant Variables and Data types

Stapes in learning C
• Stapes of learning C is similar to learning English language.

Stapes in learning English language:


Alphabets Words Sentences Paragraphs

Stapes in learning C:

Alphabets Constants
Digits Variables Instructions Program
Special symbols Keywords
Character Set of C
Character set is used to represent the information.

Character set categories:


1. Letters
2. Digits
3. Special characters
4. White spaces

Letters (Alphabets)

Uppercase A,B,C,………….Y,Z
Lowercase a,b,c,…………..y,z
Character Set of C…
Digits
All decimal digits 0,1,2,3,4,5,6,7,8,9

Special Characters
, Comma ‘ apostrophe
. Period (dot) “ Quotation mark
; semicolon ! Exclamation mark
: colon | vertical bar
? Question marks / slash
\ backslash ~ tilde
_ Under score $ dollar sign
% percent sign & ampersand
^ caret * asterisk
- Minus sign + plus sign
Character Set of C…
Special Characters…..

< opening angle bracket > closing angle


bracket
(or less than sign) (or greater than sign)
( left parenthesis ) right parenthesis
[ left bracket ] right bracket
{ left brace } right brace
# number sign

White Spaces

1. Blank space 2. Horizontal tab


C Tokens
Token: Smallest individual unit of program

Types:

C tokens
C tokens

Keywords
Keywords Strings
Strings Special
Special
Identifiers Constants
Identifiers Constants Operators
Operators
(float,
(float, (“abc”,
(“abc”, Symbols
Symbols
(a, rate)
(a, rate) (-15.2,10)
(-15.2,10) (+,-,)
(+,-,)
while)
while) ”year”)
”year”) (? ,, [)[)
(?
C constants
A fixed value that do not change during the execution
of program.

1. Primary constants
a. Integer constants
b. Real constant
c. Character Constant

2. Secondary Constants
a. Array
b. Pointers
c. Structure
d. Union
e. Enum etc.
Rules for Integer Constants
1. An integer constant must have at least one digit.
2. It must not have a decimal point.
3. It could be either positive or negative.
4. If no sign precedes an integer constant it is
assumed to be positive.
5. No commas and blanks are allowed within an
integer constant.
6. The allowable range for integer constant is -32768
to32767 for 16-bit computer.
Ex: 467,+789,-8000
Rules for Real Constants
1. A real constant must have at least one digit.
2. It must have a decimal point.
3. It could be either positive or negative.
4. Default sign is positive.
5. No commas or blanks are allowed within a real
constant.
Ex: +32.33
432.32
-39.3
Rules for Character Constants
1. A character constant is a single alphabet, a single
digit or a single special symbol enclosed within
single inverted commas.
2. The maximum length of a character constant can
be 1 character.
Ex: ‘A’
‘I’
‘5’
‘=’
C Variables
Variables: Quantity that may vary during program
execution.

Variable Name: Name given to locations in the


memory of computer where different constants
are stored.
• Type of variable must be same as type of constant
stored.
• Example: A constant stored in a memory location
with an integer variable name must be an integer
constant.
Rules for Variable Name
1. A variable name is any combination of 1 to 8 alphabets,
digits or underscores.
2. Some compilers allow variable names whose length could
be up to 40 characters.
3. The first character in the variable name must be an
alphabet.
4. No commas or blanks are allowed within a variable
name.
5. No special symbol other than an underscore
(like: f_name)
Ex: si_int
id_23
Rules for Variable Name…
• How is C able to differentiate between these
variables ?
• It is good practice to naming variables by meaningful
variable names.
like: for Number of year – noy
principle - prin
Rate of interest- roi
rather than using- a,b,c
C Keywords
• Words whose meaning has already been explained to the C
compiler.
• Keywords cannot be used as variable names.
• Keywords are also called ‘Reserved words’.
• There are only 32 keywords available in C.
auto double if static break
else int struct case enum
long switch char extern near
typedef const float register union
far continue return unsigned default
for short void do goto
signed while

You might also like