0% found this document useful (0 votes)
12 views19 pages

5 - C Character Set - Keywords, Variable, Constant

C character set- keywords, variables constant

Uploaded by

sharshika250
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)
12 views19 pages

5 - C Character Set - Keywords, Variable, Constant

C character set- keywords, variables constant

Uploaded by

sharshika250
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/ 19

Dr.

Mahalingam College of Engineering and


Technology, Pollachi

2023 Regulation
23CST101-Problem Solving using C
Course Outcomes

Course Outcomes

Cognitive Level
At the end of this course, students will be able to:

CO 1: Understand the fundamental concepts of


programming, such as variables, data types, control Understand
structures, and functions.

October 12, 2024 PSC-Module1 2


C Character Set
A character set defines the valid characters that can be used in a source
program or interpreted when a program is running

C Character Set

Source Execution
Character Set Character Set

Alphabets Digits Special White Escape


Characters Spaces Sequence

October 12, 2024 PSC-Module1 3


C Character Set

• Source Character Set


• It is used to construct the statements in the program.

• Executable Character Set


• These characters are employed at the time of execution i.e. they
have effects only when the program is being executed.

October 12, 2024 PSC-Module1 4


Source Character set
The basic source character set of C language includes

• 1.Letters

• a.Upper case letters :A,B,C …Z

• b.Lowercase letters: a, b, c,…z

• 2.Digits: 0,1,…9

• 3.Special Characters : , . : ; ” ! ^ & *( ) { } [ ]< > | \ ? / _ ~ etc

• White spaces : blank space, tabs ,Carriage return, New line character,
Form Feed character

October 12, 2024 PSC-Module1 5


Executable Character Set

Characters Escape Sequence

Back Space \b
Horizontal tab \t

Vertical tab \v

Newline \n

October 12, 2024 PSC-Module1 6


keywords
• Keywords are predefined or reserved words that have special meanings to
the compiler. These are part of the syntax and cannot be used as identifiers
in the program. There are 32 keywords available in c.

auto double int struct


break long else switch
case return enum typedef
char register extern union
const short float unsigned
continue signed for void
default sizeof goto volatile
do static if while

October 12, 2024 PSC-Module1 7


Quiz
• Identify keywords from the following

• enum
• if
• void
• number
• int
• continue
• extern
• label
• static
• Default

October 12, 2024 PSC-Module1 8


Identifiers
• An identifier refers to name of an object. It can be a variable name ,a label
name, a function name, a typedef name , a structure name, a union or an
enumeration
• The syntactic rules to write an identifier name in C are
• Identifier name in C can have letters, digits or underscores
• The first character of an identifier name must me a letter Or an underscore
• No special character (except underscore),blank space and comma can be used
in an identifier name
• Keyword or reserved words cannot form a valid identifier name
• The maximum number of characters allowed in an identifier name is compiler
dependent
• Case sensitive

October 12, 2024 PSC-Module1 9


Example

• First_Name

• RollNo

• _Address

• marks

October 12, 2024 PSC-Module1 10


Quiz
• Identify valid and invalid identifiers

Identifier Valid/invalid Reason


Student_Name
Student Name
break
1st_student
_name
Name&rollno
marks

October 12, 2024 PSC-Module1 11


Variables
• A variable is a container that stores a ‘value.’ In the kitchen, we have
containers storing rice, dal, sugar, etc. Similar to that variable in c
stores the value of a constant.
• Example:
Rules for naming variables in c:
1. The first character must be an alphabet
a=3 a is assigned “3”
or underscore(_).
b = 4.7 b is assigned “4.7”
2. No commas or blanks are allowed.
c = 'A' c is assigned “A”
3. No special symbol other than
underscore is allowed
4. Variable names are case sensitive

October 12, 2024 PSC-Module1 12


Quiz

• Identify which of the following are valid variables

• FirstName

• Integer

• 2name

• Name&mark

• _lastname

October 12, 2024 PSC-Module1 13


Constants
• An entity whose value doesn’t change is called a constant. Constants
are literal/fixed values assigned to variables or used directly in
expressions.

• Constants may be categorized in to:

• Numeric Constants

• Character Constants

• String Constants

October 12, 2024 PSC-Module1 14


Numeric Constants
• Numeric constants, as the name itself indicates, are those which consist of

numerals, an optional sign and an optional period. They are further divided

into two types:

• Integer Constants :A whole number is an integer constant Integer constants

do not have a decimal point.

• Real Constants :The real constants also known as floating point constants

are written in two forms

i) Fractional form, (ii) Exponential form

Examples : 456.78, -123.56, 3E4 , 23e-6 ,0.34E6

October 12, 2024 PSC-Module1 15


Character Constants
• Any character enclosed with in single quotes (‘) is called character constant.

• A character constant may be a single alphabet, single digit or single special


character placed with in single quotes. It has a maximum length of 1
character.

Examples
• ‘C’

• ‘c’

• ‘:’

• ‘*’

October 12, 2024 PSC-Module1 16


String Constants

• A string constant is a sequence of alphanumeric characters enclosed


in double quotes whose maximum length is 255 characters.

• Examples:
“My name is Krishna”

“Bible”

“Salary is 18000.00”

October 12, 2024 PSC-Module1 17


Quiz

• Identify which of the following are valid constants

• “ABC”

• ‘hello’

• Abc

• 23L

• 1,234

• 0x23

October 12, 2024 PSC-Module1 18


Thank You
October 12, 2024 PSC-Module1 19

You might also like