SlideShare a Scribd company logo
1 of 48
VARIABLES, DATA
TYPES, OPERATOR &
EXPRESSION
Chap 23/8/2016
1
Contents
 2.1 Character Set
 2.2 C Tokens
 Keywords & Identifiers
 Constants
 Integer, Floating Point,
Character, String,
 Enumeration
 2.3 Backslash characters /
Escape sequences
 2.4 Data Types in C
 2.5 Variables
 2.6 Declaration & Definition
 2.7 User-Defined Type
declarations
2.8 Operators & Expressions
Arithmetic, Relational, Logical,
Increment
Decrement , Bit wise,
Assignment,
Conditional
2.9 Type conversions in
Expressions
2.10 Implicit Type Conversion
2.11 Explicit Type Conversions
2.12 Precedence &
Associability of Operators.
3/8/2016
2
2.1 character set in c
3
3/8/2016
2.1 character set in c
3/8/2016
4
2.2 C tokens
3/8/2016
5
 Smallest individual units is called as ‘Tokens ‘
Keywords And Identifiers
3/8/2016
6
 Every C word is classified either “Keyword” or
“Identifier “.
Rules for Keywords
 Has fixed meaning
 Meaning can not be changed
 Served as basic building block for program
statement.
 Must be written in lower case
Keywords and Identifiers
3/8/2016
7
Keywords and Identifiers
3/8/2016
8
 Identifiers
Refer to names of variables , functions and arrays
Rules for identifiers
1. First character must be an alphabet (or
underscore)
2. Must consist of only letters, digits or
underscore.
3. Only first 31 characters are significant.
4. Cannot use a keyword
5. Must not contain white space
Constants
3/8/2016
9
Constants
Numeric
Constants
Integer
Constants
Real
Constants
Character
constants
Single
Character
Constants
String
Constants
Constants in C refers to fixed values and do not change during the
execution of a program
constants
3/8/2016
10
 Integer Constants
 Real Constants
can be represented as exponential format.
mantissa e exponent
Mantissa is either a real number expressed in
decimal notation or integer
The exponent is an integer number with an
optional plus or minus sign
The letter e can be written in lowercase or
uppercase.
constants
11
 Single character constants
 String constants
 Backslash Character constants – useful in output
functions
 also known as escape sequences
3/8/2016
Escape seqence
3/8/2016
12
Variables
3/8/2016
13
 A data name used to store data values
 May take different values at different times of
program execution
 Rules for variable
1. Should not be keyword
2. Should not contain white space
3. Uppercase and lower case are significant
4. Must begin with letter ( or underscore)
5. Normally should not be more than eight
characters.
Data Transformation
 Programs transform data from one form to
another
 Input data  Output data
 Stimulus  Response
 Programming languages store and process data
in various ways depending on the type of the
data; consequently, all data read, processed, or
written by a program must have a type
 Two distinguishing characteristics of a
programming language are the data types it
supports and the operations on those data types
2.4 Data types
3/8/2016
15
 C is rich in its data type.
 Variety of data type allows programmer to
select appropriate data type as per need
 ANSI supports 3 classes of data type
1. Primary or fundamental data type
2. Derived data type
3. User defined data type.
Data types in C
3/8/2016
16
Data types in C
3/8/2016
17
3/8/2016
18
19
2.8 OPERATORS AND
EXPRESSIONS
Expressions
Combination of Operators and Operands
Example 2 * y + 5
Operands
Operators
Definition
“An operator is a symbol (+,-,*,/) that directs the computer
to perform certain mathematical or logical manipulations
and is usually used to manipulate data and variables”
Ex: a+b
Operators in C
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and decrement operators
6. Conditional operators
7. Bitwise operators
8. Special operators
Arithmetic operators
Operator example Meaning
+ a + b Addition –unary
- a – b Subtraction- unary
* a * b Multiplication
/ a / b Division
% a % b Modulo division- remainder
Relational Operators
Operator Meaning
< Is less than
<= Is less than or equal to
> Is greater than
>= Is greater than or equal to
== Equal to
!= Not equal to
Logical Operators
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT
Logical expression or a compound relational
expression-
An expression that combines two or more
relational expressions
Ex: if (a==b && b==c)
Truth Table
a b
Value of the expression
a && b a || b
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1
Assignment operators
Syntax:
v op = exp;
Where v = variable,
op = shorthand assignment operator
exp = expression
Ex: x=x+3
x+=3
Shorthand Assignment operators
Simple assignment
operator
Shorthand operator
a = a+1 a + =1
a = a-1 a - =1
a = a* (m+n) a * = m+n
a = a / (m+n) a / = m+n
a = a %b a %=b
Increment & Decrement Operators
C supports 2 useful operators namely
1. Increment ++
2. Decrement – operators
The ++ operator adds a value 1 to the operand
The – operator subtracts 1 from the operand
++a or a++
--a or a--
Rules for ++ & -- operators
1. These require variables as their operands
2. When postfix either ++ or – is used with the
variable in a given expression, the expression
is evaluated first and then it is incremented or
decremented by one
3. When prefix either ++ or – is used with the
variable in a given expression, it is
incremented or decremented by one first and
then the expression is evaluated with the new
value
Examples for ++ & -- operators
Let the value of a =5 and b=++a then
a = b =6
Let the value of a = 5 and b=a++ then
a =5 but b=6
i.e.:
1. a prefix operator first adds 1 to the operand and
then the result is assigned to the variable on the
left
2. a postfix operator first assigns the value to the
variable on left and then increments the
operand.
Conditional operators
Syntax:
exp1 ? exp2 : exp3
Where exp1,exp2 and exp3 are expressions
Working of the ? Operator:
Exp1 is evaluated first, if it is nonzero(1/true) then the expression2 is
evaluated and this becomes the value of the expression,
If exp1 is false(0/zero) exp3 is evaluated and its value becomes the
value of the expression
Ex: m=2;
n=3
r=(m>n) ? m : n;
Bitwise operators
These operators allow manipulation of data at the bit level
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
<< Shift left
>> Shift right
Special operators
1. Comma operator ( ,)
2. sizeof operator – sizeof( )
3. Pointer operators – ( & and *)
4. Member selection operators – ( . and ->)
Arithmetic Expressions
Algebraic expression C expression
axb-c a*b-c
(m+n)(x+y) (m+n)*(x+y)
a*b/c
3x2+2x+1 3*x*x+2*x+1
a/b
S=(a+b+c)/2
c
ab
b
a
2
cba 
S=
Arithmetic Expressions
Algebraic expression C expression
area= area=sqrt(s*(s-a)*(s-b)*(s-c))
sin(b/sqrt(a*a+b*b))
tow1=sqrt((rowx-rowy)/2+tow*x*y*y)
tow1=sqrt(pow((rowx-rowy)/2,2)+tow*x*y*y)
y=(alpha+beta)/sin(theta*3.1416/180)+abs(x)
))()(( csbsass 
Sin








 22
ba
b
2
1
2
xy
yx


 





 

2
2
1
2
xy
yx


 





 

xy 




sin
Precedence of operators
BODMAS RULE-
Brackets of Division Multiplication Addition Subtraction
Brackets will have the highest precedence and have to be
evaluated first, then comes of , then comes
division, multiplication, addition and finally subtraction.
C language uses some rules in evaluating the expressions
and they r called as precedence rules or sometimes also
referred to as hierarchy of operations, with some operators
with highest precedence and some with least.
The 2 distinct priority levels of arithmetic operators in c are-
Highest priority : * / %
Lowest priority : + -
Rules for evaluation of expression
1. First parenthesized sub expression from left to right are
evaluated.
2. If parentheses are nested, the evaluation begins with the
innermost sub expression
3. The precedence rule is applied in determining the order of
application of operators in evaluating sub expressions
4. The associatively rule is applied when 2 or more operators of the
same precedence level appear in a sub expression.
5. Arithmetic expressions are evaluated from left to right using the
rules of precedence
6. When parentheses are used, the expressions within parentheses
assume highest priority
Hierarchy of operators
Operator Description Associativity
( ), [ ] Function call, array
element reference
Left to Right
+, -, ++, - -
,!,~,*,&
Unary plus, minus,
increment, decrement,
logical negation, 1’s
complement, pointer
reference, address
Right to Left
*, / , % Multiplication,
division, modulus
Left to Right
Example 1
Evaluate x1=(-b+ sqrt (b*b-4*a*c))/(2*a) @ a=1, b=-5, c=6
=(-(-5)+sqrt((-5)(-5)-4*1*6))/(2*1)
=(5 + sqrt((-5)(-5)-4*1*6))/(2*1)
=(5 + sqrt(25 -4*1*6))/(2*1)
=(5 + sqrt(25 -4*6))/(2*1)
=(5 + sqrt(25 -24))/(2*1)
=(5 + sqrt(1))/(2*1)
=(5 + 1.0)/(2*1)
=(6.0)/(2*1)
=6.0/2 = 3.0
Example 2
Evaluate the expression when a=4
b=a- ++a
=a – 5
=5-5
=0
Order of evaluation
3/8/2016
42
Highest () [] ->
! ~ ++ -- (type *) & sizeof
* / %
+ -
<< >>
< <= > >=
== !=
&
^
|
&&
||
? :
= += -= *= /=
Lowest ,
43
2.9 Type conversions in
expressions
 1. Implicit Type Conversion
 C permits mixing of constants and variables of
different types in an expression. C
automatically converts any intermediate values
to the proper type so that the expression can
be evaluated without loosing any significance.
This automatic conversion is known as implicit
type conversion.
 The rule of type conversion: the lower type is
automatically converted to the higher type.
44
2.14 Type conversions in
expressions for example,
 int i, x;
 float f;
 double d;
 long int li ;
 The final result of an expression is converted to the
type of the variable on the left of the assignment.
long
long
float
float
float
float
double
doubleint
x = li / i + i * f –
d
45
3.14 Type conversions in
expressions
 Conversion Hierarchy is given below
long int
Conversion
hierarchy
charshort
float
double
long double
int
unsigned long int
46
3.14 Type conversions in
expressions
 2. Explicit conversion
 We can force a type conversion in a way .
 The general form of explicit conversion is
( type-name ) expression
 for example
 x = ( int ) 7.5 ;
 a = ( int ) 21.3 / (int) 4.5;
 a = ( float ) 3 / 2 ;
 a = float ( 3 / 2 ) ;
47
2.15 Operator precedence and
Associativity
 Rules of Precedence and Associativity
 (1)Precedence rules decides the order in which
different operators are applied.
 (2)Associativity rule decide the order in which multiple
occurrences of the same level operator are applied.
 Table3.8 on page71 shows the summary of C Operators.
 for example,
 a = i +1== j || k and 3 != x
Variables, Data Types, Operator & Expression in c in detail

More Related Content

What's hot

Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programmingAppili Vamsi Krishna
 
10. switch case
10. switch case10. switch case
10. switch caseWay2itech
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Jayanshu Gundaniya
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C ProgrammingSonya Akter Rupa
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c languagesneha2494
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C ProgrammingQazi Shahzad Ali
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programmingprogramming9
 
C Programming: Structure and Union
C Programming: Structure and UnionC Programming: Structure and Union
C Programming: Structure and UnionSelvaraj Seerangan
 
Presentation on C Switch Case Statements
Presentation on C Switch Case StatementsPresentation on C Switch Case Statements
Presentation on C Switch Case StatementsDipesh Pandey
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statementRaj Parekh
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming LanguageAhmad Idrees
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements Tarun Sharma
 

What's hot (20)

Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
10. switch case
10. switch case10. switch case
10. switch case
 
Operators
OperatorsOperators
Operators
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
C functions
C functionsC functions
C functions
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
C Programming: Structure and Union
C Programming: Structure and UnionC Programming: Structure and Union
C Programming: Structure and Union
 
Presentation on C Switch Case Statements
Presentation on C Switch Case StatementsPresentation on C Switch Case Statements
Presentation on C Switch Case Statements
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 

Similar to Variables, Data Types, Operator & Expression in c in detail

C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till nowAmAn Singh
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till nowAmAn Singh
 
Chapter 3.3
Chapter 3.3Chapter 3.3
Chapter 3.3sotlsoc
 
data type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de ladata type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de laLEOFAKE
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c languageTanmay Modi
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C ProgrammingQazi Shahzad Ali
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
 
Programming presentation
Programming presentationProgramming presentation
Programming presentationFiaz Khokhar
 
Dti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpressionDti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpressionalish sha
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptxAnisZahirahAzman
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions NotesProf Ansari
 

Similar to Variables, Data Types, Operator & Expression in c in detail (20)

Coper in C
Coper in CCoper in C
Coper in C
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
Chapter 3.3
Chapter 3.3Chapter 3.3
Chapter 3.3
 
data type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de ladata type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de la
 
C program
C programC program
C program
 
Theory3
Theory3Theory3
Theory3
 
additional.pptx
additional.pptxadditional.pptx
additional.pptx
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Python
PythonPython
Python
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Programming presentation
Programming presentationProgramming presentation
Programming presentation
 
Overview of C Language
Overview of C LanguageOverview of C Language
Overview of C Language
 
Dti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpressionDti2143 chapter 3 arithmatic relation-logicalexpression
Dti2143 chapter 3 arithmatic relation-logicalexpression
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
 
1 Revision Tour
1 Revision Tour1 Revision Tour
1 Revision Tour
 
C fundamental
C fundamentalC fundamental
C fundamental
 

More from gourav kottawar

operator overloading & type conversion in cpp
operator overloading & type conversion in cppoperator overloading & type conversion in cpp
operator overloading & type conversion in cppgourav kottawar
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cppgourav kottawar
 
classes & objects in cpp
classes & objects in cppclasses & objects in cpp
classes & objects in cppgourav kottawar
 
working file handling in cpp overview
working file handling in cpp overviewworking file handling in cpp overview
working file handling in cpp overviewgourav kottawar
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cppgourav kottawar
 
exception handling in cpp
exception handling in cppexception handling in cpp
exception handling in cppgourav kottawar
 
cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basicsgourav kottawar
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++gourav kottawar
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cppgourav kottawar
 
classes & objects in cpp overview
classes & objects in cpp overviewclasses & objects in cpp overview
classes & objects in cpp overviewgourav kottawar
 
SQL || overview and detailed information about Sql
SQL || overview and detailed information about SqlSQL || overview and detailed information about Sql
SQL || overview and detailed information about Sqlgourav kottawar
 
SQL querys in detail || Sql query slides
SQL querys in detail || Sql query slidesSQL querys in detail || Sql query slides
SQL querys in detail || Sql query slidesgourav kottawar
 
Rrelational algebra in dbms overview
Rrelational algebra in dbms overviewRrelational algebra in dbms overview
Rrelational algebra in dbms overviewgourav kottawar
 
overview of database concept
overview of database conceptoverview of database concept
overview of database conceptgourav kottawar
 
Relational Model in dbms & sql database
Relational Model in dbms & sql databaseRelational Model in dbms & sql database
Relational Model in dbms & sql databasegourav kottawar
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptgourav kottawar
 

More from gourav kottawar (20)

operator overloading & type conversion in cpp
operator overloading & type conversion in cppoperator overloading & type conversion in cpp
operator overloading & type conversion in cpp
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
 
classes & objects in cpp
classes & objects in cppclasses & objects in cpp
classes & objects in cpp
 
expression in cpp
expression in cppexpression in cpp
expression in cpp
 
basics of c++
basics of c++basics of c++
basics of c++
 
working file handling in cpp overview
working file handling in cpp overviewworking file handling in cpp overview
working file handling in cpp overview
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpp
 
exception handling in cpp
exception handling in cppexception handling in cpp
exception handling in cpp
 
cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basics
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 
constructor & destructor in cpp
constructor & destructor in cppconstructor & destructor in cpp
constructor & destructor in cpp
 
basics of c++
basics of c++basics of c++
basics of c++
 
classes & objects in cpp overview
classes & objects in cpp overviewclasses & objects in cpp overview
classes & objects in cpp overview
 
expression in cpp
expression in cppexpression in cpp
expression in cpp
 
SQL || overview and detailed information about Sql
SQL || overview and detailed information about SqlSQL || overview and detailed information about Sql
SQL || overview and detailed information about Sql
 
SQL querys in detail || Sql query slides
SQL querys in detail || Sql query slidesSQL querys in detail || Sql query slides
SQL querys in detail || Sql query slides
 
Rrelational algebra in dbms overview
Rrelational algebra in dbms overviewRrelational algebra in dbms overview
Rrelational algebra in dbms overview
 
overview of database concept
overview of database conceptoverview of database concept
overview of database concept
 
Relational Model in dbms & sql database
Relational Model in dbms & sql databaseRelational Model in dbms & sql database
Relational Model in dbms & sql database
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) ppt
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

Variables, Data Types, Operator & Expression in c in detail

  • 1. VARIABLES, DATA TYPES, OPERATOR & EXPRESSION Chap 23/8/2016 1
  • 2. Contents  2.1 Character Set  2.2 C Tokens  Keywords & Identifiers  Constants  Integer, Floating Point, Character, String,  Enumeration  2.3 Backslash characters / Escape sequences  2.4 Data Types in C  2.5 Variables  2.6 Declaration & Definition  2.7 User-Defined Type declarations 2.8 Operators & Expressions Arithmetic, Relational, Logical, Increment Decrement , Bit wise, Assignment, Conditional 2.9 Type conversions in Expressions 2.10 Implicit Type Conversion 2.11 Explicit Type Conversions 2.12 Precedence & Associability of Operators. 3/8/2016 2
  • 3. 2.1 character set in c 3 3/8/2016
  • 4. 2.1 character set in c 3/8/2016 4
  • 5. 2.2 C tokens 3/8/2016 5  Smallest individual units is called as ‘Tokens ‘
  • 6. Keywords And Identifiers 3/8/2016 6  Every C word is classified either “Keyword” or “Identifier “. Rules for Keywords  Has fixed meaning  Meaning can not be changed  Served as basic building block for program statement.  Must be written in lower case
  • 8. Keywords and Identifiers 3/8/2016 8  Identifiers Refer to names of variables , functions and arrays Rules for identifiers 1. First character must be an alphabet (or underscore) 2. Must consist of only letters, digits or underscore. 3. Only first 31 characters are significant. 4. Cannot use a keyword 5. Must not contain white space
  • 10. constants 3/8/2016 10  Integer Constants  Real Constants can be represented as exponential format. mantissa e exponent Mantissa is either a real number expressed in decimal notation or integer The exponent is an integer number with an optional plus or minus sign The letter e can be written in lowercase or uppercase.
  • 11. constants 11  Single character constants  String constants  Backslash Character constants – useful in output functions  also known as escape sequences 3/8/2016
  • 13. Variables 3/8/2016 13  A data name used to store data values  May take different values at different times of program execution  Rules for variable 1. Should not be keyword 2. Should not contain white space 3. Uppercase and lower case are significant 4. Must begin with letter ( or underscore) 5. Normally should not be more than eight characters.
  • 14. Data Transformation  Programs transform data from one form to another  Input data  Output data  Stimulus  Response  Programming languages store and process data in various ways depending on the type of the data; consequently, all data read, processed, or written by a program must have a type  Two distinguishing characteristics of a programming language are the data types it supports and the operations on those data types
  • 15. 2.4 Data types 3/8/2016 15  C is rich in its data type.  Variety of data type allows programmer to select appropriate data type as per need  ANSI supports 3 classes of data type 1. Primary or fundamental data type 2. Derived data type 3. User defined data type.
  • 16. Data types in C 3/8/2016 16
  • 17. Data types in C 3/8/2016 17
  • 20. Expressions Combination of Operators and Operands Example 2 * y + 5 Operands Operators
  • 21. Definition “An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and variables” Ex: a+b
  • 22. Operators in C 1. Arithmetic operators 2. Relational operators 3. Logical operators 4. Assignment operators 5. Increment and decrement operators 6. Conditional operators 7. Bitwise operators 8. Special operators
  • 23. Arithmetic operators Operator example Meaning + a + b Addition –unary - a – b Subtraction- unary * a * b Multiplication / a / b Division % a % b Modulo division- remainder
  • 24. Relational Operators Operator Meaning < Is less than <= Is less than or equal to > Is greater than >= Is greater than or equal to == Equal to != Not equal to
  • 25. Logical Operators Operator Meaning && Logical AND || Logical OR ! Logical NOT Logical expression or a compound relational expression- An expression that combines two or more relational expressions Ex: if (a==b && b==c)
  • 26. Truth Table a b Value of the expression a && b a || b 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 1
  • 27. Assignment operators Syntax: v op = exp; Where v = variable, op = shorthand assignment operator exp = expression Ex: x=x+3 x+=3
  • 28. Shorthand Assignment operators Simple assignment operator Shorthand operator a = a+1 a + =1 a = a-1 a - =1 a = a* (m+n) a * = m+n a = a / (m+n) a / = m+n a = a %b a %=b
  • 29. Increment & Decrement Operators C supports 2 useful operators namely 1. Increment ++ 2. Decrement – operators The ++ operator adds a value 1 to the operand The – operator subtracts 1 from the operand ++a or a++ --a or a--
  • 30. Rules for ++ & -- operators 1. These require variables as their operands 2. When postfix either ++ or – is used with the variable in a given expression, the expression is evaluated first and then it is incremented or decremented by one 3. When prefix either ++ or – is used with the variable in a given expression, it is incremented or decremented by one first and then the expression is evaluated with the new value
  • 31. Examples for ++ & -- operators Let the value of a =5 and b=++a then a = b =6 Let the value of a = 5 and b=a++ then a =5 but b=6 i.e.: 1. a prefix operator first adds 1 to the operand and then the result is assigned to the variable on the left 2. a postfix operator first assigns the value to the variable on left and then increments the operand.
  • 32. Conditional operators Syntax: exp1 ? exp2 : exp3 Where exp1,exp2 and exp3 are expressions Working of the ? Operator: Exp1 is evaluated first, if it is nonzero(1/true) then the expression2 is evaluated and this becomes the value of the expression, If exp1 is false(0/zero) exp3 is evaluated and its value becomes the value of the expression Ex: m=2; n=3 r=(m>n) ? m : n;
  • 33. Bitwise operators These operators allow manipulation of data at the bit level Operator Meaning & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR << Shift left >> Shift right
  • 34. Special operators 1. Comma operator ( ,) 2. sizeof operator – sizeof( ) 3. Pointer operators – ( & and *) 4. Member selection operators – ( . and ->)
  • 35. Arithmetic Expressions Algebraic expression C expression axb-c a*b-c (m+n)(x+y) (m+n)*(x+y) a*b/c 3x2+2x+1 3*x*x+2*x+1 a/b S=(a+b+c)/2 c ab b a 2 cba  S=
  • 36. Arithmetic Expressions Algebraic expression C expression area= area=sqrt(s*(s-a)*(s-b)*(s-c)) sin(b/sqrt(a*a+b*b)) tow1=sqrt((rowx-rowy)/2+tow*x*y*y) tow1=sqrt(pow((rowx-rowy)/2,2)+tow*x*y*y) y=(alpha+beta)/sin(theta*3.1416/180)+abs(x) ))()(( csbsass  Sin          22 ba b 2 1 2 xy yx             2 2 1 2 xy yx             xy      sin
  • 37. Precedence of operators BODMAS RULE- Brackets of Division Multiplication Addition Subtraction Brackets will have the highest precedence and have to be evaluated first, then comes of , then comes division, multiplication, addition and finally subtraction. C language uses some rules in evaluating the expressions and they r called as precedence rules or sometimes also referred to as hierarchy of operations, with some operators with highest precedence and some with least. The 2 distinct priority levels of arithmetic operators in c are- Highest priority : * / % Lowest priority : + -
  • 38. Rules for evaluation of expression 1. First parenthesized sub expression from left to right are evaluated. 2. If parentheses are nested, the evaluation begins with the innermost sub expression 3. The precedence rule is applied in determining the order of application of operators in evaluating sub expressions 4. The associatively rule is applied when 2 or more operators of the same precedence level appear in a sub expression. 5. Arithmetic expressions are evaluated from left to right using the rules of precedence 6. When parentheses are used, the expressions within parentheses assume highest priority
  • 39. Hierarchy of operators Operator Description Associativity ( ), [ ] Function call, array element reference Left to Right +, -, ++, - - ,!,~,*,& Unary plus, minus, increment, decrement, logical negation, 1’s complement, pointer reference, address Right to Left *, / , % Multiplication, division, modulus Left to Right
  • 40. Example 1 Evaluate x1=(-b+ sqrt (b*b-4*a*c))/(2*a) @ a=1, b=-5, c=6 =(-(-5)+sqrt((-5)(-5)-4*1*6))/(2*1) =(5 + sqrt((-5)(-5)-4*1*6))/(2*1) =(5 + sqrt(25 -4*1*6))/(2*1) =(5 + sqrt(25 -4*6))/(2*1) =(5 + sqrt(25 -24))/(2*1) =(5 + sqrt(1))/(2*1) =(5 + 1.0)/(2*1) =(6.0)/(2*1) =6.0/2 = 3.0
  • 41. Example 2 Evaluate the expression when a=4 b=a- ++a =a – 5 =5-5 =0
  • 42. Order of evaluation 3/8/2016 42 Highest () [] -> ! ~ ++ -- (type *) & sizeof * / % + - << >> < <= > >= == != & ^ | && || ? : = += -= *= /= Lowest ,
  • 43. 43 2.9 Type conversions in expressions  1. Implicit Type Conversion  C permits mixing of constants and variables of different types in an expression. C automatically converts any intermediate values to the proper type so that the expression can be evaluated without loosing any significance. This automatic conversion is known as implicit type conversion.  The rule of type conversion: the lower type is automatically converted to the higher type.
  • 44. 44 2.14 Type conversions in expressions for example,  int i, x;  float f;  double d;  long int li ;  The final result of an expression is converted to the type of the variable on the left of the assignment. long long float float float float double doubleint x = li / i + i * f – d
  • 45. 45 3.14 Type conversions in expressions  Conversion Hierarchy is given below long int Conversion hierarchy charshort float double long double int unsigned long int
  • 46. 46 3.14 Type conversions in expressions  2. Explicit conversion  We can force a type conversion in a way .  The general form of explicit conversion is ( type-name ) expression  for example  x = ( int ) 7.5 ;  a = ( int ) 21.3 / (int) 4.5;  a = ( float ) 3 / 2 ;  a = float ( 3 / 2 ) ;
  • 47. 47 2.15 Operator precedence and Associativity  Rules of Precedence and Associativity  (1)Precedence rules decides the order in which different operators are applied.  (2)Associativity rule decide the order in which multiple occurrences of the same level operator are applied.  Table3.8 on page71 shows the summary of C Operators.  for example,  a = i +1== j || k and 3 != x