SlideShare a Scribd company logo
COMPONENT OF C LANGUAGE
(VARIABLE DATA TYPES, OPERATORS BETWEEN VARIABLES)
Variables
A variables is a temporary value that contains an identifier.
x=7
y=3
z=x+y
In the example, x and y are variables. Variable x is a memory location that has the identifier x and store
value 7 while variable y is a memory location that has the identifier x and store value 3. In the last line, z
also a variable. However, it use to hold the result of x+y. What do you think is the value held by z?
Variables
 A, B and C are variables in the pseudocode
 Variable names takes away the need for a programmer to access memory locations using their address
 The operating system takes care of allocating space for the variables
 To refer to the value in the memory space, we need to only use the variable name
Variables Names
A variable name is a user-defined identifier. There are general guidelines for variables name:
a) Do not use C identifiers such as printf, scanf, etc.
b) Do not use reserved words such as void, return, int, double, etc.
c) Digits as well as underscores are allowed
d) Do not use digits as the first characters.
Variables Names
Identifier Valid/Invalid Explanation
total Valid Valid name
_sales Valid Identifier may start with an underscore
2003sales Invalid Identifier cannot start with a digit
double Invalid It is a reserved word
puts Invalid It is an identifier
Account’s Invalid Character ‘ is not allowed
X*y Invalid Character * is not allowed
Sales2003 Valid Valid name
Net profit Invalid Spaced in between is not allowed
NETPROFIT Valid Uppercase is acceptable. However, lower case is
preferred. Upper case usually used for a constant
name
Data Types
We can store variables in our computer memory. Since each type of data takes
different amount of memory, like integer takes 2 bytes, decimal numbers take 4 byte,
and SINGLE character takes 1 byte. So, we must tell computer about the type of data
we are going to store in our variable.
1. Predefined/Inbuilt: These data type are inbuilt. E.g.: char, int, float, double
2. Derived data type: These data types are inherited from predefined data type. E.g.:
arrays, pointer.
3. User defined data type: These are created by user for his/her own purpose. E.g.:
typedef, enum, structure, union
Data Types
Data Type
Primitive
char
Int
Float
Double
Derived
Array
Pointer
Function
User
Defined
Enum
Structure
union
Data Types and its Format
Data Types and its Format
Character Set
 Character set is the set of the character
 This characters are used to form the word, numbers and expression.
 The characters in the c are grouped into the following categories.
Letters : Uppercase A…Z, Lowercase a…z
Digits : All decimal digits 0 to 9
Special Character : ,(comma) .(period) ; (semicolon) :(colon), & (ampersand), #
(number sign) etc.
White spaces : Blank Space, Horizontal Space, New Line.
Keywords
 Are simply the reserved words whose meaning has been explained in library of C
language.
 There are 32 keywords in c language.
 We can’t use keywords as identifiers or variables because if we do so we are trying
to assign a new meaning to the keyword, which is not allowed by the computer
int float;
char if;
int void;
Above will give ERROR as we are using keywords as identifier or variable name
List of Keywords
Constant
 Constant names are usually all in upper case to differentiate them from variable
names.
First method: A constant is declared like a variable, except that keywords const is
added before the variable’s data type:
const int DOZEN = 12;
const double PI = 3.14;
Second method: a constant is defined using the #define pre=processor. #define is a
directive that cause the computer to replace the identifier with value it is to.
example:
#define PI 3.14
Identifier
Value
Backslash character constant
 C supports special backslash character constants that are used in output functions.
 These character combinations are known as escape sequences.
Comments
 Comments are that part of program, which are ignored by compiler. These are used
for better readability of user. Compiler doesn‘t compile the text written inside
comments.
 The comment describes the purpose of the code in the file and might include some
license or copyright information.
 It is not compulsory to have comments in our program, but its good practice and
what most C programmers will expect to find.
1. Single Line Comment : // is used to make single line comment. All the text in a
line after // will become part of comment and will be ignored by compiler. E.g.,
int a; // this is ignored
2. Multiline Comment: This starts from /* and ends at */. All the text in between
these will be part of comment. E.g., /* This Is Multiline Comment */
Input/Output
 Almost all C programs have at least one output statement. Otherwise, the program
won’t output anything on the screen and there is no knowing if the program ran
successfully or not.
 The most common input/output functions are printf() and scanf() both of which are
defined in the header file stdio.h.
 Use printf() (Print with Format) for outputting data to the console and scanf() (Scan
with Format) for inputting data from the keyboard.
Input/Output [printf ( )]
 The syntax of the printf() function is
 Format is the typesetting of the output that you can control, and argument is a list
of variables to be printed.
 The printf() function prints the value(s) of variables in argument to the standard
output (screen) following the formatting command defined by format.
Input/Output [scanf ( )]
 The scanf() is the inverse of printf(), i.e., it scans the value(s) of variable(s) from the
standard input (keyboard) with format. The formatting part (i.e., % …) in scanf() is the
same as printf(). However, the variable name must be preceded by an &
(ampersand).
OPERATORS BETWEEN VARIABLES
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 several categories. They include:
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Increment and Decrement operators
Arithmetic Operators
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 modular 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.
Mix-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: 15 / 10.0 = 1.5
Relational Operators
 The relational operators are mathematical operators often used in the if statement.
 It is important to understand the difference between a single equal sign (=) and
double equal signs (==) as the single equal sign (=) is used for an assignment while
the double equal signs (==) are used as mathematical equality.
Relational Operators
1. if (a==b) printf("a and b are equal.n");
else printf("a and b are not equal.n");
The statement above means that if the two variables, a and b, are the same, a string, “a and b
are equal.”, is printed, otherwise a string, “a and b are not equal.”, is printed.
One equal sign is for assignment and two equal signs are for logical equality. The double equal
signs in C are equivalent to the equal sign in regular mathematical equations.
Relational Operators
1. a = 10;
a = a + 1;
The statement a = a + 1 does not make sense as a mathematical expression. However, it makes
perfect sense as a C statement. a + 1 is first evaluated to be 11 and this value of 11 is then
assigned to a. Effectively, the value of a was incremented by 1.
Logical Operators
 Logical operators in C are mostly used within the if statement.
Logical Operators
Increment/Decrement/Substitution 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—
Increment/Decrement/Substitution Operators
Rules for ++ & -- operators
 These require variables as their operands.
 When postfix either ++ or – is used with the variable in each 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 each expression, it is
incremented or decremented by one first and then the expression is evaluated with
the new value
Increment/Decrement/Substitution Operators
Shorthand notations for assignment operations
EXERCISE
1. Print a character, “a”.
2. Print an integer 10
3. Print floating number 10.5
4. Print two floating numbers, 10.0 and -2.3
5. Write a program that reads temperature in Celsius and convert it to Fahrenheit.
Note
𝐶 = 𝐹 − 32 𝑋
5
9
Expected result

More Related Content

Similar to component of c language.pptx

Token and operators
Token and operatorsToken and operators
Token and operators
Samsil Arefin
 
C basics
C basicsC basics
C basics
sridevi5983
 
C basics
C basicsC basics
C basics
sridevi5983
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators ppt
Viraj Shah
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III TermAndrew Raj
 
3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx
3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx
3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx
LeenaChaudhari24
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2dplunkett
 
Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03hassaanciit
 
Basics of c
Basics of cBasics of c
Basics of c
vinothini1996
 
Basics of c++
Basics of c++ Basics of c++
Basics of c++
Gunjan Mathur
 
C notes for exam preparation
C notes for exam preparationC notes for exam preparation
C notes for exam preparation
Lakshmi Sarvani Videla
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
Ashwini Rao
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
Don Dooley
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
Rokonuzzaman Rony
 

Similar to component of c language.pptx (20)

Token and operators
Token and operatorsToken and operators
Token and operators
 
C basics
C basicsC basics
C basics
 
C basics
C basicsC basics
C basics
 
Ch02
Ch02Ch02
Ch02
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
C language
C languageC language
C language
 
Unit 1
Unit 1Unit 1
Unit 1
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators ppt
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
 
3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx
3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx
3110003_PPS_GTU_Study_Material_Presentations_Unit-2_18122020041700AM (1).pptx
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2
 
What is c
What is cWhat is c
What is c
 
Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03Introduction to Computer and Programming - Lecture 03
Introduction to Computer and Programming - Lecture 03
 
Basics of c
Basics of cBasics of c
Basics of c
 
Basics of c++
Basics of c++ Basics of c++
Basics of c++
 
C notes for exam preparation
C notes for exam preparationC notes for exam preparation
C notes for exam preparation
 
5 introduction-to-c
5 introduction-to-c5 introduction-to-c
5 introduction-to-c
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 

More from AnisZahirahAzman

Chapter 6.pdf
Chapter 6.pdfChapter 6.pdf
Chapter 6.pdf
AnisZahirahAzman
 
Chapter 4.pdf
Chapter 4.pdfChapter 4.pdf
Chapter 4.pdf
AnisZahirahAzman
 
Chapter 10.pdf
Chapter 10.pdfChapter 10.pdf
Chapter 10.pdf
AnisZahirahAzman
 
Chapter 3.pdf
Chapter 3.pdfChapter 3.pdf
Chapter 3.pdf
AnisZahirahAzman
 
Chapter 2.pdf
Chapter 2.pdfChapter 2.pdf
Chapter 2.pdf
AnisZahirahAzman
 
Chapter 1.pdf
Chapter 1.pdfChapter 1.pdf
Chapter 1.pdf
AnisZahirahAzman
 
Chapter 2.pdf
Chapter 2.pdfChapter 2.pdf
Chapter 2.pdf
AnisZahirahAzman
 
Chapter 1.pdf
Chapter 1.pdfChapter 1.pdf
Chapter 1.pdf
AnisZahirahAzman
 
Chapter 1.pdf
Chapter 1.pdfChapter 1.pdf
Chapter 1.pdf
AnisZahirahAzman
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
AnisZahirahAzman
 
Chapter 9.pptx
Chapter 9.pptxChapter 9.pptx
Chapter 9.pptx
AnisZahirahAzman
 
connecting smart object in IoT.pptx
connecting smart object in IoT.pptxconnecting smart object in IoT.pptx
connecting smart object in IoT.pptx
AnisZahirahAzman
 
Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptx
AnisZahirahAzman
 
introduction to c.pptx
introduction to c.pptxintroduction to c.pptx
introduction to c.pptx
AnisZahirahAzman
 

More from AnisZahirahAzman (15)

Chapter 6.pdf
Chapter 6.pdfChapter 6.pdf
Chapter 6.pdf
 
Chapter 4.pdf
Chapter 4.pdfChapter 4.pdf
Chapter 4.pdf
 
Chapter 10.pdf
Chapter 10.pdfChapter 10.pdf
Chapter 10.pdf
 
Chapter 3.pdf
Chapter 3.pdfChapter 3.pdf
Chapter 3.pdf
 
Chapter 2.pdf
Chapter 2.pdfChapter 2.pdf
Chapter 2.pdf
 
Chapter 1.pdf
Chapter 1.pdfChapter 1.pdf
Chapter 1.pdf
 
Chapter 2.pdf
Chapter 2.pdfChapter 2.pdf
Chapter 2.pdf
 
Chapter 1.pdf
Chapter 1.pdfChapter 1.pdf
Chapter 1.pdf
 
Chapter 1.pdf
Chapter 1.pdfChapter 1.pdf
Chapter 1.pdf
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 
IoT Protocol Stack.pdf
IoT Protocol Stack.pdfIoT Protocol Stack.pdf
IoT Protocol Stack.pdf
 
Chapter 9.pptx
Chapter 9.pptxChapter 9.pptx
Chapter 9.pptx
 
connecting smart object in IoT.pptx
connecting smart object in IoT.pptxconnecting smart object in IoT.pptx
connecting smart object in IoT.pptx
 
Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptx
 
introduction to c.pptx
introduction to c.pptxintroduction to c.pptx
introduction to c.pptx
 

Recently uploaded

power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 

Recently uploaded (20)

power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 

component of c language.pptx

  • 1. COMPONENT OF C LANGUAGE (VARIABLE DATA TYPES, OPERATORS BETWEEN VARIABLES)
  • 2. Variables A variables is a temporary value that contains an identifier. x=7 y=3 z=x+y In the example, x and y are variables. Variable x is a memory location that has the identifier x and store value 7 while variable y is a memory location that has the identifier x and store value 3. In the last line, z also a variable. However, it use to hold the result of x+y. What do you think is the value held by z?
  • 3. Variables  A, B and C are variables in the pseudocode  Variable names takes away the need for a programmer to access memory locations using their address  The operating system takes care of allocating space for the variables  To refer to the value in the memory space, we need to only use the variable name
  • 4. Variables Names A variable name is a user-defined identifier. There are general guidelines for variables name: a) Do not use C identifiers such as printf, scanf, etc. b) Do not use reserved words such as void, return, int, double, etc. c) Digits as well as underscores are allowed d) Do not use digits as the first characters.
  • 5. Variables Names Identifier Valid/Invalid Explanation total Valid Valid name _sales Valid Identifier may start with an underscore 2003sales Invalid Identifier cannot start with a digit double Invalid It is a reserved word puts Invalid It is an identifier Account’s Invalid Character ‘ is not allowed X*y Invalid Character * is not allowed Sales2003 Valid Valid name Net profit Invalid Spaced in between is not allowed NETPROFIT Valid Uppercase is acceptable. However, lower case is preferred. Upper case usually used for a constant name
  • 6. Data Types We can store variables in our computer memory. Since each type of data takes different amount of memory, like integer takes 2 bytes, decimal numbers take 4 byte, and SINGLE character takes 1 byte. So, we must tell computer about the type of data we are going to store in our variable. 1. Predefined/Inbuilt: These data type are inbuilt. E.g.: char, int, float, double 2. Derived data type: These data types are inherited from predefined data type. E.g.: arrays, pointer. 3. User defined data type: These are created by user for his/her own purpose. E.g.: typedef, enum, structure, union
  • 8. Data Types and its Format
  • 9. Data Types and its Format
  • 10. Character Set  Character set is the set of the character  This characters are used to form the word, numbers and expression.  The characters in the c are grouped into the following categories. Letters : Uppercase A…Z, Lowercase a…z Digits : All decimal digits 0 to 9 Special Character : ,(comma) .(period) ; (semicolon) :(colon), & (ampersand), # (number sign) etc. White spaces : Blank Space, Horizontal Space, New Line.
  • 11. Keywords  Are simply the reserved words whose meaning has been explained in library of C language.  There are 32 keywords in c language.  We can’t use keywords as identifiers or variables because if we do so we are trying to assign a new meaning to the keyword, which is not allowed by the computer int float; char if; int void; Above will give ERROR as we are using keywords as identifier or variable name
  • 13. Constant  Constant names are usually all in upper case to differentiate them from variable names. First method: A constant is declared like a variable, except that keywords const is added before the variable’s data type: const int DOZEN = 12; const double PI = 3.14; Second method: a constant is defined using the #define pre=processor. #define is a directive that cause the computer to replace the identifier with value it is to. example: #define PI 3.14 Identifier Value
  • 14. Backslash character constant  C supports special backslash character constants that are used in output functions.  These character combinations are known as escape sequences.
  • 15. Comments  Comments are that part of program, which are ignored by compiler. These are used for better readability of user. Compiler doesn‘t compile the text written inside comments.  The comment describes the purpose of the code in the file and might include some license or copyright information.  It is not compulsory to have comments in our program, but its good practice and what most C programmers will expect to find. 1. Single Line Comment : // is used to make single line comment. All the text in a line after // will become part of comment and will be ignored by compiler. E.g., int a; // this is ignored 2. Multiline Comment: This starts from /* and ends at */. All the text in between these will be part of comment. E.g., /* This Is Multiline Comment */
  • 16. Input/Output  Almost all C programs have at least one output statement. Otherwise, the program won’t output anything on the screen and there is no knowing if the program ran successfully or not.  The most common input/output functions are printf() and scanf() both of which are defined in the header file stdio.h.  Use printf() (Print with Format) for outputting data to the console and scanf() (Scan with Format) for inputting data from the keyboard.
  • 17. Input/Output [printf ( )]  The syntax of the printf() function is  Format is the typesetting of the output that you can control, and argument is a list of variables to be printed.  The printf() function prints the value(s) of variables in argument to the standard output (screen) following the formatting command defined by format.
  • 18. Input/Output [scanf ( )]  The scanf() is the inverse of printf(), i.e., it scans the value(s) of variable(s) from the standard input (keyboard) with format. The formatting part (i.e., % …) in scanf() is the same as printf(). However, the variable name must be preceded by an & (ampersand).
  • 20. 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 several categories. They include: 1. Arithmetic operators 2. Relational operators 3. Logical operators 4. Increment and Decrement operators
  • 22. 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 modular 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
  • 23. 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.
  • 24. Mix-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: 15 / 10.0 = 1.5
  • 25. Relational Operators  The relational operators are mathematical operators often used in the if statement.  It is important to understand the difference between a single equal sign (=) and double equal signs (==) as the single equal sign (=) is used for an assignment while the double equal signs (==) are used as mathematical equality.
  • 26. Relational Operators 1. if (a==b) printf("a and b are equal.n"); else printf("a and b are not equal.n"); The statement above means that if the two variables, a and b, are the same, a string, “a and b are equal.”, is printed, otherwise a string, “a and b are not equal.”, is printed. One equal sign is for assignment and two equal signs are for logical equality. The double equal signs in C are equivalent to the equal sign in regular mathematical equations.
  • 27. Relational Operators 1. a = 10; a = a + 1; The statement a = a + 1 does not make sense as a mathematical expression. However, it makes perfect sense as a C statement. a + 1 is first evaluated to be 11 and this value of 11 is then assigned to a. Effectively, the value of a was incremented by 1.
  • 28. Logical Operators  Logical operators in C are mostly used within the if statement.
  • 30. Increment/Decrement/Substitution 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—
  • 31. Increment/Decrement/Substitution Operators Rules for ++ & -- operators  These require variables as their operands.  When postfix either ++ or – is used with the variable in each 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 each expression, it is incremented or decremented by one first and then the expression is evaluated with the new value
  • 33. EXERCISE 1. Print a character, “a”. 2. Print an integer 10 3. Print floating number 10.5 4. Print two floating numbers, 10.0 and -2.3 5. Write a program that reads temperature in Celsius and convert it to Fahrenheit. Note 𝐶 = 𝐹 − 32 𝑋 5 9 Expected result

Editor's Notes

  1. NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image.