0% found this document useful (0 votes)
14 views14 pages

CL - 7chpt2 Overview of C Part 3

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)
14 views14 pages

CL - 7chpt2 Overview of C Part 3

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/ 14

Class VII

Computer
Application

Chapter 2
Overview of C (part 3)
Sub Topic:Constants, variables and
data types

Presented By,
M. Siva Shankari,
CPSV
Constants, variables and data
types
A program is a sequence of instructions. These
instructions are formed by certain symbols and words
according to some rules. C has its own vocabulary &
grammar.
Character sets

Keywords & Identifier

constants

Variables

Data types
Character set:

Using characters we can form words,


numbers and expressions. The characters
in C are grouped into following categories.

Created By, M. Siva Shankari @ CPSV


Keywords & Identifiers

Keywords are the words, which have fixed meaning and


these meaning cannot be changed. It is also known as
reserved words.

Identifiers refers to the name of variables, functions and


arrays. These are user defined names and consists of a
sequence of letters and digits with the letter as first
character.
CONSTANTs
constants in C means fixed values that do not change
during the execution of a program.

Example : consider the equation 5X+4Y, here 5 and 4


cannot change, they are called constants.
INTERGER CONSTANTS

An integer constant refers to a sequence of digits. Integer


consist of a set of digits, 0 to 9, preceded by an optional –
or + sign.

Valid examples of decimal integer constants are,


223,-567, 6758777, +67 etc..

Space, comma, and non digit characters are not permitted.

Invalid interger are,


15, 45, 34,500, $2787 etc

REAL CONSTANTS

The number containing fractional parts like 23.567 are


called real or floating point constants.

examples are,
0.68, 45.677, 23.0 etc..
SINGLE CHARACTER CONSTANTS

It contains a single character enclosed with in a pair


of sigle quote.
Example: ‘5’, ‘g’ etc

STRING CONSTANTS

A string constants is a sequence of characters


enclosed in double quotes. The character may be
letters, numbers, special charcters and blank space.
Examples are,
“welcome”, “65768”, “wow!”

Created By, M. Siva Shankari @ CPSV


BACKSLASH CHARACTER CONSTANTS

It is an unprintable ASCII characters which can


perform special functions in the output statement
Example:

Created By, M. Siva Shankari @ CPSV


Variables
 Variable is an identifier, which denotes a storage
location used to store a data value
 A variable is a container which holds the value while
the Java program is executed.
 A variable is assigned with a data type.
 Variable is a name of memory location.
 It is a combination of "vary + able" that means its value
can be changed.
 Declaring (Creating) Variables
Syntax: type variable = value;
Where type is one of Java's types (such as int or String),
and variable is the name of the variable (such as x
or name). The equal sign is used to assign values to
the variable.

Example: String name =


"John";
char ch = 'A';
Variable Naming conventions
1) Variable names may consists letters, digits, _(underscore) & dollar
($).
2)Variables naming cannot contain white spaces, for
example: int num ber = 100; // is invalid
because the variable name has space in it.
3) Variable name can begin with special characters such as $ and _
4) As per the java coding standards the variable name should begin
with a lower case letter,
for example: int num;
5) Variable names are case sensitive in C.
6) It should not be a Keyword.
7) Variable names can be of any length.
Data Types in C
 Data type defines the values that a
variable can take
 Data types specify the different sizes
and values that can be stored in the
variable.
Data Type Meaning Size(in bytes)
char A character 1
Short int An integer 2
Long int An integer 4
Float A single 4
precision real
number
Double A double 8
precision real
number

Created By, M. Siva Shankari @ CPSV


Identify invalid
constants and why?

1.999
2.14,000
3.0.00001

Created By, M. Siva Shankari @ CPSV

You might also like