SlideShare ist ein Scribd-Unternehmen logo
1 von 66
Data Types and Variables in ‘C’ language
Course: BCA
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)

Weitere ähnliche Inhalte

Was ist angesagt?

Character Array and String
Character Array and StringCharacter Array and String
Character Array and StringTasnima Hamid
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C ProgrammingQazi Shahzad Ali
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++Neeru Mittal
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programmingprogramming9
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C LanguageAdnan Khan
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILEDipta Saha
 
Constants and variables in c programming
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programmingChitrank Dixit
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programmingRumman Ansari
 

Was ist angesagt? (20)

Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Strings
StringsStrings
Strings
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
 
C++ string
C++ stringC++ string
C++ string
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
C++
C++C++
C++
 
Typecasting in c
Typecasting in cTypecasting in c
Typecasting in c
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Enums in c
Enums in cEnums in c
Enums in c
 
Constants and variables in c programming
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programming
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
 
ASSIGNMENT STATEMENTS AND
ASSIGNMENT STATEMENTS ANDASSIGNMENT STATEMENTS AND
ASSIGNMENT STATEMENTS AND
 
Loops c++
Loops c++Loops c++
Loops c++
 

Andere mochten auch

Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ LanguageWay2itech
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGAbhishek Dwivedi
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGEPRASANYA K
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit orderMalikireddy Bramhananda Reddy
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)Ashishchinu
 
General Tips to Overcome an Interview
General Tips to Overcome an InterviewGeneral Tips to Overcome an Interview
General Tips to Overcome an InterviewPratik Patel
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data typesManisha Keim
 
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C LanguageSurbhi Yadav
 
Calculus II - 15
Calculus II - 15Calculus II - 15
Calculus II - 15David Mao
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2MOHIT TOMAR
 
Test solutions of computer languages
Test solutions of computer languagesTest solutions of computer languages
Test solutions of computer languagesmanish katara
 

Andere mochten auch (20)

Data types
Data typesData types
Data types
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
C ppt
C pptC ppt
C ppt
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
 
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
C notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit orderC notes by m v b  reddy(gitam)imp  notes  all units notes  5 unit order
C notes by m v b reddy(gitam)imp notes all units notes 5 unit order
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
1.2 variables in c
1.2 variables in c1.2 variables in c
1.2 variables in c
 
Variables_c
Variables_cVariables_c
Variables_c
 
General Tips to Overcome an Interview
General Tips to Overcome an InterviewGeneral Tips to Overcome an Interview
General Tips to Overcome an Interview
 
Apa style-1 (1)
Apa style-1 (1)Apa style-1 (1)
Apa style-1 (1)
 
C pointers
C pointersC pointers
C pointers
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
 
Calculus II - 15
Calculus II - 15Calculus II - 15
Calculus II - 15
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 
C data_structures
C  data_structuresC  data_structures
C data_structures
 
Test solutions of computer languages
Test solutions of computer languagesTest solutions of computer languages
Test solutions of computer languages
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 

Ähnlich wie datatypes and variables in c language

Ähnlich wie datatypes and variables in c language (20)

C presentation book
C presentation bookC presentation book
C presentation book
 
C introduction
C introductionC introduction
C introduction
 
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
 
Chap 1 and 2
Chap 1 and 2Chap 1 and 2
Chap 1 and 2
 
Cnotes
CnotesCnotes
Cnotes
 
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
 
fds unit1.docx
fds unit1.docxfds unit1.docx
fds unit1.docx
 
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
 
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++
 
Lecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C ProgrammingLecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C Programming
 
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
 
C PADHLO FRANDS.pdf
C PADHLO FRANDS.pdfC PADHLO FRANDS.pdf
C PADHLO FRANDS.pdf
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
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
 
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
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Kürzlich hochgeladen (20)

Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
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
 
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
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

datatypes and variables in c language

  • 1. Data Types and Variables in ‘C’ language Course: BCA 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)