SlideShare a Scribd company logo
1 of 66
Data Types and Variables in ‘C’ language
Course: MCA
Subject: Programming In C Language
Basic structure of C programming
 To write a C program, we first create functions and then put them together. A C program may contain one
or more sections. They are illustrated below.

 Documentation section
 Link section
 Definition section
 Global declaration section
 main () Function section
 {
 Declaration part
 Executable part


 }
 Subprogram section
 Function 1
 Function 2
 …………..
 …………..
 Function n (User defined functions)
Programming Rules
 Basic rules to begin:
 In separate statement each instruction should be
written. Therefore , complete C program consist of set
of instructions.
 The statements in program must be written in
sequencial order to get desired output.Unless any logic
problem can be arise.
 All statement should written in small case letters.
 C has no particular rules for position at which
statement is to be typed.
 In C program every statement must end with ;
(semicolon).It act as a terminator.
Rules for Comment
 Comment in the program should be enclosed within /* .. */ .Look example below the first line
is comment.
For ex. /*This my first program*/
#include<stdio.h>
main()
{
Statement;
Statement;
}
 Though comments are not necessary, but it good practice to begin program with comment
indicating purpose of program so that other person can get idea of program.
 You can write any number comment at any place in program mentioning the purpose of the
statement.
 Use few Comment instead of too many.
 A comment cannot be nested. For ex., /* The/* first/*program*/*/*/.
 A comment can split over more than one line. For ex.
/*THE
First
Program*/
Main Method
 main() is a collection of the set of statements. Statements are
always enclosed belongs to main() within pairs of {} (opening
and closing braces).For ex.
void main()
{
1st statement;
2nd statement;
}
 Technically main() is a function because every function has
the pair of parentheses ( ) associated with it.
 The function in c have their return type, Similarly, If we want
that main() function should not return any value of particular
type precede it with void ,int etc.
Declaration
 Any variable used in the program must be declared
before using it. For ex,
int a,b,c; /*declaration*/
float a,b,c; /*declaration*/
a=a+b; /*usage*/
For declaration see the datatype table as follow
Datatype number Declaration format string
Integer 1,+5,-5 int a; "%d", a
 Float 11.363,+1.14,-12.11 float a; "%f", a
 Double +1.123123,-1.234345 double a; "%l", a
 Character 'A','B' char a; "%c",a
 String "Dev.com" char a[20]; "%c",a
Ways of declaration in C lets see:
a) While declaration you can also initialize it as
int a=1,b=24; , float a=1.5, b=1.98+3.8*2.7;
b) The order sometimes matter in initialization.
For ex.
int i = 1, j=24; is same as int j=24,j=1;
float a=1.8 , b= 3.1+a;
IT is alright but float b =3.1+a ,a=1.8; is not this why we have to initialize a
before.
c) Lets another statements:
int x,y,z;
x=y=z=10; work perfectly
int x=y=z=10; not work because once again
we are trying to use y (assign to y) before defining it.
Character Set
 Character set are the set of alphabets, letters and some
special characters that are valid in C language.
 Alphabets:
 Uppercase: A B C .................................... X Y Z
 Lowercase: a b c ...................................... x y z
 Digits:
 0 1 2 3 4 5 6 8 9
Cont..
 Special Characters in C language
, <> . _ () ; $ : % [] # ? ‘ & {} “ ^ ! * / | -  ~
 White space Characters:
blank space, new line, horizontal tab, carriage return
and form feed
Tri-graph Characters
 Many non-English keyboards do not support all the characters.
 ANSI C introduces the concept of “Trigraph” sequences to provide a
way to enter certain characters that are not available on some
keyboards.
The Six Kinds of Tokens in ANSI C
 Keywords
 Identifiers
 Constants
 String Constants
 Operators
 Punctuators
C Token
Keywords
Keywords are C tokens that have a strict meaning.
They are explicitly reserved and cannot be redefined.
ANSII C has 32 key words
ANSII C Keywords
auto do goto signed unsigned
break double if sizeof void
case else int static volatile
char enum long struct while
const extern register switch
continue float return typedef
default for short union
Identifier
 In C programming, identifiers are names given to C
entities, such as variables, functions, structures etc.
Identifier are created to give unique name to C entities to
identify it during the execution of program.
 For example:
int money;
int mango_tree;
 Here, money is a identifier which denotes a variable of type
integer. Similarly, mango_tree is another identifier, which
denotes another variable of type integer
Rules for Identifier
First letter must be alphabet(Underscore)
An identifier can be composed of letters (both
uppercase and lowercase letters),digits and underscore
'_' only.
The first 31 characters of an identifier
Cannot use Keyword
Must not contain white space
Constants
Integer Constants
 Integer Constants
 An integer constant refers to a sequence of digits, There are three types integers, namely,
decimal, octal, and hexa decimal.
 Decimal Constant
Eg:123,-321 etc.,
Note: Embedded spaces, commas and non-digit characters are not permitted
 between digits.
Eg: 1) 15 750 2)$1000
 Octal Constant
An octal integer constant consists of any combination of digits from the set 0 through 7, with a
leading 0.
 Eg: 1) 037 2) 0435
 Hexadecimal Constant
A sequence of digits preceded by 0x or 0X is considered as hexadecimal integer. They may
also include alphabets A through F or a through f.
 Eg: 1) 0X2 2) 0x9F 3) 0Xbcd
 Program for representation of integer constants on a 16-bit computer.
 /*Integer numbers on a 16-bit machine*/
 main()
 {
 printf(“Integer valuesnn”);
 printf(“%d%d%dn”,32767,32767+1,32767+10);
 printf(“n”);
 printf(“Long integer valuesnn”);
 printf(“%ld%ld%ldn”,32767L,32767L+1L,32767L+10L);
 }
 OUTPUT
 Integer values
 32767 -32768 -32759
 Long integer values
 32767 32768 32777
Real Constants
 Certain quantities that vary continuously, such as distances,
heights etc., are represented by numbers containing
functional parts like 17.548.
 Such numbers are called real(or floating point)constants.
 Eg:0.0083,-0.75 etc.,
 A real number may also be expressed in exponential or
scientific notation.
 Eg:215.65 may be written as 2.1565e2
 A single character constants contains a single
character enclosed within a pair of single quote
marks.
 Eg: ’5’
 ‘X’
 ‘;’
Single Character Constant
String Constants
 A string constant is a sequence of characters
enclosed in double quotes.
 The characters may be letters, numbers, special
characters and blank space.
 Eg:”Hello!”
“1987”
“?….!”
Backslash Character Constants
 C supports special backslash character constants that
are used in output functions.
 These character combinations are known as escape
sequences.
VARIABLES
 Definition:
A variable is a data name that may be used to
store a data value. A variable may take different
values at different times of execution and may be
chosen by the programmer in a meaningful way.
 It may consist of letters, digits and underscore
character.
Eg: 1) Average
2) Height
 They must begin with a letter. Some systems permit underscore as
the first character .
 ANSI standard recognizes a length of 31 characters.
 However, the length should not be normally more than eight
characters.
 Uppercase and lowercase are significant. The variable name should
not be a keyword.
 Uppercase and lowercase are significant.
 The variable name should not be a keyword.
 White space is not allowed.
Rules for defining variables
Cont..
 Valid Variables Names:
 John Value T_raise
 Delhi x1 ph_value
mark sum1 distance
Invalid Variable Names:
123 (area)
% 25th
DATA TYPES
 A data type is
 A set of values AND
 A set of operations on those values
 A data type is used to
 Identify the type of a variable when the variable is
declared
 Identify the type of the return value of a function
 Identify the type of a parameter expected by a function
Data Types
 ANSI C supports four classes of data types.
1. Primary or Fundamental data types.
2. User-defined data types.
3. Derived data types.
4. Empty data set.
Primary Data Types in C
Integer Types
Size and Range Of Data types on 16 bit machine
Floating Point Types
DECLARATION OF VARIABLES
 Declarations does two things:
 It tells the compiler what the variable name is
 It specifies what type of data the variable will hold
 Primary Type Declaration
 The syntax is
 Data-type v1,v2…..vn;
Eg:
int count;
double ratio, total;
User-defined type declaration
 C allows user to define an identifier that would represent an existing int
data type.
 The general form is typedef type identifier;
Eg:
typedef int units;
typedef float marks;
 Another user defined data types is enumerated data type which can be
used to declare variables that can have one of the values enclosed
within the braces.
 enum identifier {value1,value2,……valuen};
Declaration of storage class
 Variables in C can have not only data type but also storage
class that provides information about their locality and
visibility.
 /*Example of storage class*/
int m;
main()
{
int i;
float bal;
……
……
function1();
}
function1()
{
int i;
float sum;
……
……
}
 Here the variable m is called
the global variable. It can be
used in all the functions in
the program.
 The variables bal, sum and i
are called local variables.
Local variables are visible and
meaningful only inside the
function in which they are
declared.
 There are four storage class
specifies, namely, auto, static,
register and exte
Cont..
ASSIGNING VALUES TO VARIABLES
 The syntax is
 Variable_name=constant
 Eg:
int a=20;
bal=75.84;
yes=’x’;
 C permits multiple assignments in one line.
Example:
initial_value=0;final_value=100;
Declaring a variable as constant
Eg:
const int class_size=40;
 This tells the compiler that the value of the int variable
class_size must not be modified by the program.
Declaring a variable as volatile
 By declaring a variable as volatile, its value may be changed
at any time by some external source.
Eg:
volatile int date;
READING DATA FROM KEYWORD
 Another way of giving values to variables is to input data
through keyboard using the scanf function.
 The general format of scanf is as follows.
scanf(“control string”,&variable1,&variable2,….);
 The ampersand symbol & before each variable name is an
operator that specifies the variable name’s address.
 Eg:
scanf(“%d”,&number);
OPERATORS OF C
 C supports a rich set of operators. Operators are used in programs to
manipulate data and variables.
 They usually form a part of the mathematical of logical expressions.
 C operators are classified into a number of categories. They include:
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
Eg:
1) a-b 2) a+b 3) a*b 4) p%q
Integer Arithmetic
 When both the operands in a single arithmetic
expression are integers, the expression is called an
integer expression , and the operation is called integer
arithmetic.
 During modulo division the sign of the result is always
the sign of the first operand.That is
 -14 % 3 = -2
 -14 % -3 = -2
 14 % -3 = 2
Real Arithmetic
 An arithmetic operation involving only real operands
is called real arithmetic. If x and y are floats then we
will have:
1) x = 6.0 / 7.0 = 0.857143
2) y = 1.0 / 3.0 = 0.333333
 The operator % cannot be used with real operands.
Mixed-mode Arithmetic
 When one of the operands is real and the other is
integer, the expression is called a mixed-mode
arithmetic expression and its result is always a real
number.
 Eg:
1) 15 / 10.0 = 1.5
RELATIONAL OPERATORS
 Comparisons can be done with
the help of relational operators.
 The expression containing a
relational operator is termed as a
relational expression.
 The value of a relational
expression is either one or zero.
LOGICAL OPERATORS
C has the following three logical operators.
 Eg:
if(age>55 && sal<1000)
if(number<0 || number>100)
ASSIGNMENT OPERATORS
 The usual assignment operator is ‘=’.
 In addition, C has a set of ‘shorthand’ assignment
operators of the form,
v op = exp;
 Eg: x += y+1;
 This is same as the statement
 x=x+(y+1);
Shorthand Assignment Operator
INCREMENT AND DECREMENT
OPERATORS
 C has two very useful operators that are not generally
found in other languages.
 These are the increment and decrement operator:
 ++ and --
 The operator ++ adds 1 to the operands while – subtracts 1.
 It takes the following form:
 ++m; or m++
 --m; or m—
Rules for ++ & -- operators
 These require variables as their operands
 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
 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
CONDITIONAL OPERATOR
 A ternary operator pair “?:” is available in C to construct
conditional expression of the form:
exp1 ? exp2 : exp3;
 Here exp1 is evaluated first. If it is true then the expression exp2
is evaluated and becomes the value of the expression. If exp1 is
false then exp3 is evaluated and its value becomes the value of
the expression.
 Eg:
if(a>b)
x = a;
else
x = b;
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.
Examples for ++ & -- operators
BITWISE OPERATORS
SPECIAL OPERATORS
 C supports some special operators such as
 Comma operator
 Size of operator
Pointer operators(& and *) and
Member selection operators(. and ->)
The Comma Operator
 The comma operator can be used to link the related expressions together. A comma
linked list of expressions are evaluated left to right and the value of right-most
expression is the value of the combined expression.
 Eg: value = (x = 10, y = 5, x + y);
 This statement first assigns the value 10 to x, then assigns 5 to y, and finally
assigns15(i.e, 10+5) to value.
The Size of Operator
 The size of is a compiler time operator and, when used with an operand, it returns the
 number of bytes the operand occupies.
 Eg: 1) m = sizeof(sum);
 2) n = sizeof(long int)
 3) k = sizeof(235L
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 : + -
Precedence of operators
EXPRESSIONS
 The combination of operators and operands is said to
be an expression.
 An arithmetic expression is a combination of variables,
constants, and operators
 arranged as per the syntax of the language.
 Eg 1) a = x + y;
Arithmetic Expressions
An arithmetic expression is a combination of variables, constants, and
operatorsarranged as per the syntax of the language.
Eg 1) a = x + y;
EVALUATION OF EXPRESSIONS
 Expressions are evaluated using an assignment statement of
the form variable = expression;
 Eg:
1) x = a * b – c;
2) y = b / c * a;
 An arithmetic expression without parenthesis will be evaluated
from left to right using the rule of precedence of operators.
 There are two distinct priority levels of arithmetic operators in
C.
 High priority * / %
 Low priority + -
PRECEDENCE OF ARITHMETIC OPERATORS
 /*Evaluation of expressions*/
main()
{
float a, b, c, y, x, z;
a = 9;
b = 12;
c = 3;
x = a – b / 3 + c * 2 – 1;
y = a – b / (3 + c) * (2 – 1);
z = a – (b / (3 + c) * 2) – 1;
printf(“x = %f n”,x);
printf(“y = %f n”,y);
printf(“z = %f n”,z);
}
OUTPUT
 x = 10.000000
 y = 7.000000
 z = 4.000000
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
TYPE CONVERSION IN EXPRESSIONS
 C permits the mixing of constants and variables of different
types in an expression.
 If the operands are of different types, the lower type is
automatically converted to higher type before the
operation proceeds. The result is of the higher type.
 Given below are the sequence of rules that are applied
while evaluating expressions.
Explicit Conversion
 C performs type conversion automatically. However,
there are instances when we want to force a type
conversion in a way that is different from the automatic
conversion.
 Eg:
 ratio = female_number / male_number
 Since female_number and male_number are declared as
integers the ratio would resent a wrong figure.
 Hence it should be converted to float.
ratio = (float) female_number / male_number
 The general form of a cast is:
(type-name)expression
MATHEMATICAL FUNCTIONS
 Mathematical functions such as sqrt, cos, log etc., are
the most frequently used ones.
 To use the mathematical functions in a C program, we
should include the line
#include<math.h>
in the beginning of the program
References:
1. Programming in C by yashwant kanitkar
2. ANSI C by E.balagurusamy- TMG publication
3. Computer programming and Utilization by sanjay shah Mahajan Publication
4. www.cprogramming.com/books.html
5. en.wikipedia.org/wiki/C_(programming_language)
6. www.programmingsimplified.com/c-program-example
7. http://cm.bell-labs.com/cm/cs/who/dmr/chist.html
8. http://en.wikipedia.org/wiki/datatypes in c language
9. http://en.wikipedia.org/wiki/List_of_C-based_programming_languages
10. http://en.wikipedia.org/wiki/C_(programming_language)

More Related Content

What's hot

Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programmingprogramming9
 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programmingChitrank Dixit
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiSowmyaJyothi3
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGAbhishek Dwivedi
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c languageRai University
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C ProgrammingQazi Shahzad Ali
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C ProgrammingKamal Acharya
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_outputAnil Dutt
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ LanguageWay2itech
 
Complete Tokens in c/c++
Complete Tokens in c/c++Complete Tokens in c/c++
Complete Tokens in c/c++Shobi P P
 
Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constantsvinay arora
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii pptJStalinAsstProfessor
 

What's hot (18)

Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programming
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
5 introduction-to-c
5 introduction-to-c5 introduction-to-c
5 introduction-to-c
 
Lecture02(constants, variable & data types)
Lecture02(constants, variable & data types)Lecture02(constants, variable & data types)
Lecture02(constants, variable & data types)
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
 
C Tokens
C TokensC Tokens
C Tokens
 
C tokens
C tokensC tokens
C tokens
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
C material
C materialC material
C material
 
Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_output
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Complete Tokens in c/c++
Complete Tokens in c/c++Complete Tokens in c/c++
Complete Tokens in c/c++
 
Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constants
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii ppt
 

Similar to Mca i pic u-2 datatypes and variables in c language

Similar to Mca i pic u-2 datatypes and variables in c language (20)

C presentation book
C presentation bookC presentation book
C presentation book
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
Cnotes
CnotesCnotes
Cnotes
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
C programming notes
C programming notesC programming notes
C programming notes
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
 
Lecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C ProgrammingLecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C Programming
 
fds unit1.docx
fds unit1.docxfds unit1.docx
fds unit1.docx
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
All C ppt.ppt
All C ppt.pptAll C ppt.ppt
All C ppt.ppt
 
Basics of c
Basics of cBasics of c
Basics of c
 
C
CC
C
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
Module 1 PCD.docx
Module 1 PCD.docxModule 1 PCD.docx
Module 1 PCD.docx
 
PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 
C PADHLO FRANDS.pdf
C PADHLO FRANDS.pdfC PADHLO FRANDS.pdf
C PADHLO FRANDS.pdf
 

More from Rai University

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University Rai University
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,Rai University
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02Rai University
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditureRai University
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public financeRai University
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introductionRai University
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflationRai University
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economicsRai University
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructureRai University
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competitionRai University
 

More from Rai University (20)

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University
 
Mm unit 4point2
Mm unit 4point2Mm unit 4point2
Mm unit 4point2
 
Mm unit 4point1
Mm unit 4point1Mm unit 4point1
Mm unit 4point1
 
Mm unit 4point3
Mm unit 4point3Mm unit 4point3
Mm unit 4point3
 
Mm unit 3point2
Mm unit 3point2Mm unit 3point2
Mm unit 3point2
 
Mm unit 3point1
Mm unit 3point1Mm unit 3point1
Mm unit 3point1
 
Mm unit 2point2
Mm unit 2point2Mm unit 2point2
Mm unit 2point2
 
Mm unit 2 point 1
Mm unit 2 point 1Mm unit 2 point 1
Mm unit 2 point 1
 
Mm unit 1point3
Mm unit 1point3Mm unit 1point3
Mm unit 1point3
 
Mm unit 1point2
Mm unit 1point2Mm unit 1point2
Mm unit 1point2
 
Mm unit 1point1
Mm unit 1point1Mm unit 1point1
Mm unit 1point1
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditure
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public finance
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introduction
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflation
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economics
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructure
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competition
 

Recently uploaded

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 

Recently uploaded (20)

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 

Mca i pic u-2 datatypes and variables in c language

  • 1. Data Types and Variables in ‘C’ language Course: MCA Subject: Programming In C Language
  • 2. Basic structure of C programming  To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are illustrated below.   Documentation section  Link section  Definition section  Global declaration section  main () Function section  {  Declaration part  Executable part    }  Subprogram section  Function 1  Function 2  …………..  …………..  Function n (User defined functions)
  • 3. Programming Rules  Basic rules to begin:  In separate statement each instruction should be written. Therefore , complete C program consist of set of instructions.  The statements in program must be written in sequencial order to get desired output.Unless any logic problem can be arise.  All statement should written in small case letters.  C has no particular rules for position at which statement is to be typed.  In C program every statement must end with ; (semicolon).It act as a terminator.
  • 4. Rules for Comment  Comment in the program should be enclosed within /* .. */ .Look example below the first line is comment. For ex. /*This my first program*/ #include<stdio.h> main() { Statement; Statement; }  Though comments are not necessary, but it good practice to begin program with comment indicating purpose of program so that other person can get idea of program.  You can write any number comment at any place in program mentioning the purpose of the statement.  Use few Comment instead of too many.  A comment cannot be nested. For ex., /* The/* first/*program*/*/*/.  A comment can split over more than one line. For ex. /*THE First Program*/
  • 5. Main Method  main() is a collection of the set of statements. Statements are always enclosed belongs to main() within pairs of {} (opening and closing braces).For ex. void main() { 1st statement; 2nd statement; }  Technically main() is a function because every function has the pair of parentheses ( ) associated with it.  The function in c have their return type, Similarly, If we want that main() function should not return any value of particular type precede it with void ,int etc.
  • 6. Declaration  Any variable used in the program must be declared before using it. For ex, int a,b,c; /*declaration*/ float a,b,c; /*declaration*/ a=a+b; /*usage*/
  • 7. For declaration see the datatype table as follow Datatype number Declaration format string Integer 1,+5,-5 int a; "%d", a  Float 11.363,+1.14,-12.11 float a; "%f", a  Double +1.123123,-1.234345 double a; "%l", a  Character 'A','B' char a; "%c",a  String "Dev.com" char a[20]; "%c",a
  • 8. Ways of declaration in C lets see: a) While declaration you can also initialize it as int a=1,b=24; , float a=1.5, b=1.98+3.8*2.7; b) The order sometimes matter in initialization. For ex. int i = 1, j=24; is same as int j=24,j=1; float a=1.8 , b= 3.1+a; IT is alright but float b =3.1+a ,a=1.8; is not this why we have to initialize a before. c) Lets another statements: int x,y,z; x=y=z=10; work perfectly int x=y=z=10; not work because once again we are trying to use y (assign to y) before defining it.
  • 9. Character Set  Character set are the set of alphabets, letters and some special characters that are valid in C language.  Alphabets:  Uppercase: A B C .................................... X Y Z  Lowercase: a b c ...................................... x y z  Digits:  0 1 2 3 4 5 6 8 9
  • 10. Cont..  Special Characters in C language , <> . _ () ; $ : % [] # ? ‘ & {} “ ^ ! * / | - ~  White space Characters: blank space, new line, horizontal tab, carriage return and form feed
  • 11. Tri-graph Characters  Many non-English keyboards do not support all the characters.  ANSI C introduces the concept of “Trigraph” sequences to provide a way to enter certain characters that are not available on some keyboards.
  • 12. The Six Kinds of Tokens in ANSI C  Keywords  Identifiers  Constants  String Constants  Operators  Punctuators
  • 14. Keywords Keywords are C tokens that have a strict meaning. They are explicitly reserved and cannot be redefined. ANSII C has 32 key words
  • 15. ANSII C Keywords auto do goto signed unsigned break double if sizeof void case else int static volatile char enum long struct while const extern register switch continue float return typedef default for short union
  • 16. Identifier  In C programming, identifiers are names given to C entities, such as variables, functions, structures etc. Identifier are created to give unique name to C entities to identify it during the execution of program.  For example: int money; int mango_tree;  Here, money is a identifier which denotes a variable of type integer. Similarly, mango_tree is another identifier, which denotes another variable of type integer
  • 17. Rules for Identifier First letter must be alphabet(Underscore) An identifier can be composed of letters (both uppercase and lowercase letters),digits and underscore '_' only. The first 31 characters of an identifier Cannot use Keyword Must not contain white space
  • 19. Integer Constants  Integer Constants  An integer constant refers to a sequence of digits, There are three types integers, namely, decimal, octal, and hexa decimal.  Decimal Constant Eg:123,-321 etc., Note: Embedded spaces, commas and non-digit characters are not permitted  between digits. Eg: 1) 15 750 2)$1000  Octal Constant An octal integer constant consists of any combination of digits from the set 0 through 7, with a leading 0.  Eg: 1) 037 2) 0435  Hexadecimal Constant A sequence of digits preceded by 0x or 0X is considered as hexadecimal integer. They may also include alphabets A through F or a through f.  Eg: 1) 0X2 2) 0x9F 3) 0Xbcd
  • 20.  Program for representation of integer constants on a 16-bit computer.  /*Integer numbers on a 16-bit machine*/  main()  {  printf(“Integer valuesnn”);  printf(“%d%d%dn”,32767,32767+1,32767+10);  printf(“n”);  printf(“Long integer valuesnn”);  printf(“%ld%ld%ldn”,32767L,32767L+1L,32767L+10L);  }  OUTPUT  Integer values  32767 -32768 -32759  Long integer values  32767 32768 32777
  • 21. Real Constants  Certain quantities that vary continuously, such as distances, heights etc., are represented by numbers containing functional parts like 17.548.  Such numbers are called real(or floating point)constants.  Eg:0.0083,-0.75 etc.,  A real number may also be expressed in exponential or scientific notation.  Eg:215.65 may be written as 2.1565e2
  • 22.  A single character constants contains a single character enclosed within a pair of single quote marks.  Eg: ’5’  ‘X’  ‘;’ Single Character Constant
  • 23. String Constants  A string constant is a sequence of characters enclosed in double quotes.  The characters may be letters, numbers, special characters and blank space.  Eg:”Hello!” “1987” “?….!”
  • 24. Backslash Character Constants  C supports special backslash character constants that are used in output functions.  These character combinations are known as escape sequences.
  • 25. VARIABLES  Definition: A variable is a data name that may be used to store a data value. A variable may take different values at different times of execution and may be chosen by the programmer in a meaningful way.  It may consist of letters, digits and underscore character. Eg: 1) Average 2) Height
  • 26.  They must begin with a letter. Some systems permit underscore as the first character .  ANSI standard recognizes a length of 31 characters.  However, the length should not be normally more than eight characters.  Uppercase and lowercase are significant. The variable name should not be a keyword.  Uppercase and lowercase are significant.  The variable name should not be a keyword.  White space is not allowed. Rules for defining variables
  • 27. Cont..  Valid Variables Names:  John Value T_raise  Delhi x1 ph_value mark sum1 distance Invalid Variable Names: 123 (area) % 25th
  • 28. DATA TYPES  A data type is  A set of values AND  A set of operations on those values  A data type is used to  Identify the type of a variable when the variable is declared  Identify the type of the return value of a function  Identify the type of a parameter expected by a function
  • 29. Data Types  ANSI C supports four classes of data types. 1. Primary or Fundamental data types. 2. User-defined data types. 3. Derived data types. 4. Empty data set.
  • 31. Integer Types Size and Range Of Data types on 16 bit machine
  • 33. DECLARATION OF VARIABLES  Declarations does two things:  It tells the compiler what the variable name is  It specifies what type of data the variable will hold  Primary Type Declaration  The syntax is  Data-type v1,v2…..vn; Eg: int count; double ratio, total;
  • 34. User-defined type declaration  C allows user to define an identifier that would represent an existing int data type.  The general form is typedef type identifier; Eg: typedef int units; typedef float marks;  Another user defined data types is enumerated data type which can be used to declare variables that can have one of the values enclosed within the braces.  enum identifier {value1,value2,……valuen};
  • 35. Declaration of storage class  Variables in C can have not only data type but also storage class that provides information about their locality and visibility.  /*Example of storage class*/ int m; main() { int i; float bal; …… …… function1(); } function1() { int i; float sum; …… …… }  Here the variable m is called the global variable. It can be used in all the functions in the program.  The variables bal, sum and i are called local variables. Local variables are visible and meaningful only inside the function in which they are declared.  There are four storage class specifies, namely, auto, static, register and exte
  • 37. ASSIGNING VALUES TO VARIABLES  The syntax is  Variable_name=constant  Eg: int a=20; bal=75.84; yes=’x’;  C permits multiple assignments in one line. Example: initial_value=0;final_value=100;
  • 38. Declaring a variable as constant Eg: const int class_size=40;  This tells the compiler that the value of the int variable class_size must not be modified by the program. Declaring a variable as volatile  By declaring a variable as volatile, its value may be changed at any time by some external source. Eg: volatile int date;
  • 39. READING DATA FROM KEYWORD  Another way of giving values to variables is to input data through keyboard using the scanf function.  The general format of scanf is as follows. scanf(“control string”,&variable1,&variable2,….);  The ampersand symbol & before each variable name is an operator that specifies the variable name’s address.  Eg: scanf(“%d”,&number);
  • 40. OPERATORS OF C  C supports a rich set of operators. Operators are used in programs to manipulate data and variables.  They usually form a part of the mathematical of logical expressions.  C operators are classified into a number of categories. They include: 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
  • 41. ARITHMETIC OPERATORS Eg: 1) a-b 2) a+b 3) a*b 4) p%q
  • 42. Integer Arithmetic  When both the operands in a single arithmetic expression are integers, the expression is called an integer expression , and the operation is called integer arithmetic.  During modulo division the sign of the result is always the sign of the first operand.That is  -14 % 3 = -2  -14 % -3 = -2  14 % -3 = 2
  • 43. Real Arithmetic  An arithmetic operation involving only real operands is called real arithmetic. If x and y are floats then we will have: 1) x = 6.0 / 7.0 = 0.857143 2) y = 1.0 / 3.0 = 0.333333  The operator % cannot be used with real operands.
  • 44. Mixed-mode Arithmetic  When one of the operands is real and the other is integer, the expression is called a mixed-mode arithmetic expression and its result is always a real number.  Eg: 1) 15 / 10.0 = 1.5
  • 45. RELATIONAL OPERATORS  Comparisons can be done with the help of relational operators.  The expression containing a relational operator is termed as a relational expression.  The value of a relational expression is either one or zero.
  • 46. LOGICAL OPERATORS C has the following three logical operators.  Eg: if(age>55 && sal<1000) if(number<0 || number>100)
  • 47. ASSIGNMENT OPERATORS  The usual assignment operator is ‘=’.  In addition, C has a set of ‘shorthand’ assignment operators of the form, v op = exp;  Eg: x += y+1;  This is same as the statement  x=x+(y+1);
  • 49. INCREMENT AND DECREMENT OPERATORS  C has two very useful operators that are not generally found in other languages.  These are the increment and decrement operator:  ++ and --  The operator ++ adds 1 to the operands while – subtracts 1.  It takes the following form:  ++m; or m++  --m; or m—
  • 50. Rules for ++ & -- operators  These require variables as their operands  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  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
  • 51. CONDITIONAL OPERATOR  A ternary operator pair “?:” is available in C to construct conditional expression of the form: exp1 ? exp2 : exp3;  Here exp1 is evaluated first. If it is true then the expression exp2 is evaluated and becomes the value of the expression. If exp1 is false then exp3 is evaluated and its value becomes the value of the expression.  Eg: if(a>b) x = a; else x = b;
  • 52. 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. Examples for ++ & -- operators
  • 54. SPECIAL OPERATORS  C supports some special operators such as  Comma operator  Size of operator Pointer operators(& and *) and Member selection operators(. and ->)
  • 55. The Comma Operator  The comma operator can be used to link the related expressions together. A comma linked list of expressions are evaluated left to right and the value of right-most expression is the value of the combined expression.  Eg: value = (x = 10, y = 5, x + y);  This statement first assigns the value 10 to x, then assigns 5 to y, and finally assigns15(i.e, 10+5) to value. The Size of Operator  The size of is a compiler time operator and, when used with an operand, it returns the  number of bytes the operand occupies.  Eg: 1) m = sizeof(sum);  2) n = sizeof(long int)  3) k = sizeof(235L
  • 56. 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 : + - Precedence of operators
  • 57. EXPRESSIONS  The combination of operators and operands is said to be an expression.  An arithmetic expression is a combination of variables, constants, and operators  arranged as per the syntax of the language.  Eg 1) a = x + y;
  • 58. Arithmetic Expressions An arithmetic expression is a combination of variables, constants, and operatorsarranged as per the syntax of the language. Eg 1) a = x + y;
  • 59. EVALUATION OF EXPRESSIONS  Expressions are evaluated using an assignment statement of the form variable = expression;  Eg: 1) x = a * b – c; 2) y = b / c * a;  An arithmetic expression without parenthesis will be evaluated from left to right using the rule of precedence of operators.  There are two distinct priority levels of arithmetic operators in C.  High priority * / %  Low priority + -
  • 60. PRECEDENCE OF ARITHMETIC OPERATORS  /*Evaluation of expressions*/ main() { float a, b, c, y, x, z; a = 9; b = 12; c = 3; x = a – b / 3 + c * 2 – 1; y = a – b / (3 + c) * (2 – 1); z = a – (b / (3 + c) * 2) – 1; printf(“x = %f n”,x); printf(“y = %f n”,y); printf(“z = %f n”,z); } OUTPUT  x = 10.000000  y = 7.000000  z = 4.000000
  • 61. 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
  • 62. TYPE CONVERSION IN EXPRESSIONS  C permits the mixing of constants and variables of different types in an expression.  If the operands are of different types, the lower type is automatically converted to higher type before the operation proceeds. The result is of the higher type.  Given below are the sequence of rules that are applied while evaluating expressions.
  • 63. Explicit Conversion  C performs type conversion automatically. However, there are instances when we want to force a type conversion in a way that is different from the automatic conversion.  Eg:  ratio = female_number / male_number  Since female_number and male_number are declared as integers the ratio would resent a wrong figure.  Hence it should be converted to float. ratio = (float) female_number / male_number  The general form of a cast is: (type-name)expression
  • 64. MATHEMATICAL FUNCTIONS  Mathematical functions such as sqrt, cos, log etc., are the most frequently used ones.  To use the mathematical functions in a C program, we should include the line #include<math.h> in the beginning of the program
  • 65.
  • 66. References: 1. Programming in C by yashwant kanitkar 2. ANSI C by E.balagurusamy- TMG publication 3. Computer programming and Utilization by sanjay shah Mahajan Publication 4. www.cprogramming.com/books.html 5. en.wikipedia.org/wiki/C_(programming_language) 6. www.programmingsimplified.com/c-program-example 7. http://cm.bell-labs.com/cm/cs/who/dmr/chist.html 8. http://en.wikipedia.org/wiki/datatypes in c language 9. http://en.wikipedia.org/wiki/List_of_C-based_programming_languages 10. http://en.wikipedia.org/wiki/C_(programming_language)