SlideShare a Scribd company logo
1 of 37
VARIABLES, CONSTANTS,
OPERATORS, EXPRESSIONS AND
STATEMENTS
By: John Paul Espino
De La Salle University – Dasmarinas
Facebook.com/Johnpaul.dss
KEYWORDS
• Reserved words that have a special meaning.
• May not be redefined by the programmer.
32 KEYWORDS
• auto
• break
• case
• char
• const
• continue
• default
• do
• double
• else
• enum
• extern
• float
• for
• goto
• if
• int
• long
• register
• return
• short
• signed
• sizeof
• static
• struct
• switch
• typedef
• union
• unsigned
• void
• volatile
• while
LITERALS
• values that identifiers can hold.
• Numeric literals – accepts numeric values
• No comma
• No space between unary sign and the digits
• Must begin and end with a digit
• Non-numeric literals - may be a character or sequence of characters
• Example:
‘a’
‘+’
‘B’
“De La Salle University”
“BCS”
IDENTIFIERS
• are the names that are used to reference variables, function labels and various
user-defined objects.
RULES FOR NAMING VALID IDENTIFIERS
1. An identifier in Turbo C can vary from 1 to 32 characters.
2. The first letter must be a letter or an underscore (_), followed optionally by sequence of letters, digits
and/or underscore.
RULES FOR NAMING VALID IDENTIFIERS
3. Turbo C also allows the $ to be used in an identifier name, but this is non-standard so it’s use is not
recommended.
4. An identifier should not include embedded blanks.
5. You cannot use any of the Turbo C keyword as your variable or identifier name.
6. You should not call your variable by the same name as other functions.
EXERCISES
Identify the if the identifier is valid or invalid.
1. _
2. a$
3. Hello_World
4. _1
5. A
6. main
7. scanf
8. num1
9. tot sales
10. x-1
11. lname
12. Void
Invalid: 2,3,6,7,9,10
Valid: 1,4,5,8,11,12
integer1 45
integer2 72
sum 117
VARIABLES
• are identifiers in C where we want to store values (data).
Variables are important since they contain the values need for
manipulation and evaluation. Variable names are stored in the
computer’s memory.
TYPE BITWIDTH RANGE
char 8 0 to 255
int 16 -32768 to 32767
float 32 3.4E-32 to 3.4 E+38
double 64 1.7E-308 to 1.7 E+308
void 0 valueless
DATA TYPES
 type of data that a variable can hold
TYPE EXAMPLES
char ‘A’ ‘b’ ‘$’ ‘9’ ‘ab’‘10’
int 1 250 4500
float 3.5 42.56 345.6789
double 3.5647290… 486.145875...
void valueless
MORE ON DATA TYPES
TYPE MODIFIERS
 is used to alter the meaning of the base type to fit the needs of various situations more precisely.
 The four type modifiers in C are:
signed unsigned
long short
 Note:
 Type modifiers can be applied to char and int except long which can also be applied to double
TYPE BITWIDTH RANGE
long int 32 -2147483648 to 2147483647
short int 16 -32768 to 32767
signed 32 -2147483648 to 2147483647
long int
unsigned 32 0 to 4294967295
long int
SOME COMBINATIONS OF C’S BASIC
DATA TYPES AND MODIFIERS
DECLARATION OF VARIABLES
• All variables must be declared before they are used.
• Syntax:
type variable_list;
• where:
type is a valid data type
variable_list is 1 or more identifier names with comma separator
Local variables are variables that are declared inside a function.
They are also called automatic variables. Local variables can
only be referenced by statements that are inside the block in
which the variables are declared.
Example:
#include <stdio.h>
main ()
{
int a,b,c;
}
Function block
LOCAL VARIABLES
Example:
#include <stdio.h>
int a,b,c;
main ()
{
}
GLOBAL VARIABLES
• variables are known throughout the entire program and may be used by any
piece of code. Also, they will hold their values during the entire execution of the
program. Global variables are created by declaring them outside any function.
Example:
#include <stdio.h>
main ()
{
int a,b,c;
}
Example:
#include <stdio.h>
int a,b,c;
main ()
{
}
LOCAL
VARIABLES
GLOBAL
VARIABLES
Example:
#include <stdio.h>
main ()
{
}
test_function (int a, float b);
{
}
FORMAL PARAMETERS
• behave like local variables in a function. Their
declaration occurs inside parentheses that follow the
function name.
CONSTANTS
• Constants refer to fixed values that may not be
altered by the program.
• Turbo C supports one other type of constant in
addition to those of the pre-defined data types. This
is known as the string. All string constants are
enclosed in double quote (“”).
• Example: #define TEXT “Hello World”
•
DECLARATION OF CONSTANT
• are identifiers that can store a value that cannot be changed during program
execution.
const type iden_name = value;
where:
type is a valid data type
iden_name is a valid identifier
value is a constant value of the identifier
ASSIGNMENT STATEMENT
Recall the assignment statement in flowcharting
The general form of an assignment statement is
var_name = expression
where:
var_name should be a variable, not a function or
constant.
expression may be a single constant or a
complex combination of variables, operators and
constants.
Number = 5
Examples:
char ch = ‘a’;
int first = 0;
float num = 1.5;
type var_name = constant
You can give variables a value at the time they are declared
by placing an equal sign (=) and a constant after the variable
name. This is called initialization and it’s general form is:
semicolon
VARIABLE INITIALIZATION
• Global variables are initialized at the start of
the program
• Local variables are initialized each time the
block in which they are declared is entered
• All global and local variables are initialized to
zero (0) if no other initialization is specified.
REMINDERS IN INITIALIZATION
Variables of type const may not be changed
during execution of the program. Variables
of this type get value from initialization or by
some hardware-dependent means.
The modifier volatile is used to tell the
compiler that a variable’s value can be
changed in ways not explicitly specified by
the program.
ACCESS MODIFIERS
REVIEW EXERCISES
1. Variables of type ___________are used to hold
integer quantities.
2. Values of type character are used to hold
________characters or any 8-bit quantity.
3. __________in C are reserved words that have
special meaning.
4. Values of type ________ and ________ are used
to hold real numbers.
5. Real numbers have both an ________ and a
fractional component.
int
ASCII
Keywords
float double
integer
6. Identifiers are composed of ________, ________, and underscore.
7. Variables that are declared inside a function are called
______________.
8. _________ are identifiers that can store a value that cannot be
changed.
letters
digits
local variables
Constants
OPERATORS
• Symbol that tells the compiler to perform specific mathematical or logical manipulations.
• Classification
• arithmetic operators
• relational operators
• logical operators
A. ARITHMETIC OPERATORS
- subtraction, unary minus
+addition
*multiplication
/ division
% modulus division
-- decrement
++ incrementNote:
• When / is applied to an integer, any remainder is truncated
• % cannot be used on type float or double
B. RELATIONAL & LOGICAL OPERATORS
• Relational Operators shows the relationship values have with one another.
• Logical operators show the ways these relationships can be connected together using rules of formal
logic.
RELATIONAL OPERATORS
Operator Action
> greater than
>= greater than or equal to
< less than
<= less than or equal to
= = equal
!= not equal
C. LOGICAL OPERATORS
&& AND
|| OR
! NOT
EXPRESSION
• Is any valid combination of operators, constants and variables that evaluates to a value.
OPERATOR PRECEDENCE
 ()
 !, unary +, unary –
 *, /, %
 Binary +, binary –
 <, <=, >, >=
 ==, !=
 &&
 ||
highest
lowest
EVALUATE THE FOLLOWING:
1. Given: z = 5; a = 3, b = 9, w = 2, y = -5
Expression:
z – a * b / 2 + w * y
2. Given: a = 5, b = 2, y = 3, c = 4, x = 1
Expression:
(a * b + 2) * -y / ( c + x )
-18
7
3. Given: dei = 0; y = 4.0; z = 2.0; x = 3.0
Expression:
!dei || ( y + z >= x – z )
4. Given: x = 3; y = 2; j = 5; k = 3
Expression:
(x-y) <= (j-k ==3)
1
0

More Related Content

What's hot

text in multimedia
text in multimediatext in multimedia
text in multimediawasrse
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and FlowchartsDeva Singh
 
Peripheral devices
Peripheral devicesPeripheral devices
Peripheral devicesBurhan Ahmed
 
Coding standards
Coding standardsCoding standards
Coding standardsMimoh Ojha
 
Attributes of output Primitive
Attributes of output Primitive Attributes of output Primitive
Attributes of output Primitive SachiniGunawardana
 
Graphics software
Graphics softwareGraphics software
Graphics softwareMohd Arif
 
Device Drivers
Device DriversDevice Drivers
Device DriversSuhas S R
 
Computer Troubleshooting
Computer TroubleshootingComputer Troubleshooting
Computer TroubleshootingLisa Hartman
 
User account (Windows)
User account (Windows)User account (Windows)
User account (Windows)Dev Dorse
 
Computer Programming: Chapter 1
Computer Programming: Chapter 1Computer Programming: Chapter 1
Computer Programming: Chapter 1Atit Patumvan
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and LexemeA. S. M. Shafi
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data typesPratik Devmurari
 
Assembler design options
Assembler design optionsAssembler design options
Assembler design optionsMohd Arif
 
Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in PythonSumit Satam
 
Embedded os
Embedded osEmbedded os
Embedded oschian417
 

What's hot (20)

History of c++
History of c++ History of c++
History of c++
 
text in multimedia
text in multimediatext in multimedia
text in multimedia
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
Peripheral devices
Peripheral devicesPeripheral devices
Peripheral devices
 
Computer Programming - Lecture 1
Computer Programming - Lecture 1Computer Programming - Lecture 1
Computer Programming - Lecture 1
 
Coding standards
Coding standardsCoding standards
Coding standards
 
Attributes of output Primitive
Attributes of output Primitive Attributes of output Primitive
Attributes of output Primitive
 
Graphics software
Graphics softwareGraphics software
Graphics software
 
Device Drivers
Device DriversDevice Drivers
Device Drivers
 
Computer Troubleshooting
Computer TroubleshootingComputer Troubleshooting
Computer Troubleshooting
 
User account (Windows)
User account (Windows)User account (Windows)
User account (Windows)
 
Computer Programming: Chapter 1
Computer Programming: Chapter 1Computer Programming: Chapter 1
Computer Programming: Chapter 1
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
 
Computer software
Computer softwareComputer software
Computer software
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
 
Assembler design options
Assembler design optionsAssembler design options
Assembler design options
 
C++ Problem solving
C++ Problem solvingC++ Problem solving
C++ Problem solving
 
Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in Python
 
Embedded os
Embedded osEmbedded os
Embedded os
 
Computer programming concepts
Computer programming conceptsComputer programming concepts
Computer programming concepts
 

Similar to Computer programming - variables constants operators expressions and statements

Introduction to c
Introduction to cIntroduction to c
Introduction to cAjeet Kumar
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming LanguageCSE 1201: Structured Programming Language
CSE 1201: Structured Programming LanguageZubayer Farazi
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Rasan Samarasinghe
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageDr.Florence Dayana
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
Escape Sequences and Variables
Escape Sequences and VariablesEscape Sequences and Variables
Escape Sequences and Variablesyarkhosh
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingEric Chou
 
CP c++ programing project Unit 1 intro.pdf
CP c++ programing project  Unit 1 intro.pdfCP c++ programing project  Unit 1 intro.pdf
CP c++ programing project Unit 1 intro.pdfShivamYadav886008
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
introductory concepts
introductory conceptsintroductory concepts
introductory conceptsWalepak Ubi
 
Basic of c language
Basic of c languageBasic of c language
Basic of c languagesunilchute1
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxMamataAnilgod
 

Similar to Computer programming - variables constants operators expressions and statements (20)

Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming LanguageCSE 1201: Structured Programming Language
CSE 1201: Structured Programming Language
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 
Ma3696 Lecture 3
Ma3696 Lecture 3Ma3696 Lecture 3
Ma3696 Lecture 3
 
C programming language
C programming languageC programming language
C programming language
 
Escape Sequences and Variables
Escape Sequences and VariablesEscape Sequences and Variables
Escape Sequences and Variables
 
C intro
C introC intro
C intro
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
C Language Part 1
C Language Part 1C Language Part 1
C Language Part 1
 
c#.pptx
c#.pptxc#.pptx
c#.pptx
 
CP c++ programing project Unit 1 intro.pdf
CP c++ programing project  Unit 1 intro.pdfCP c++ programing project  Unit 1 intro.pdf
CP c++ programing project Unit 1 intro.pdf
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
introductory concepts
introductory conceptsintroductory concepts
introductory concepts
 
Pc module1
Pc module1Pc module1
Pc module1
 
Basic of c language
Basic of c languageBasic of c language
Basic of c language
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptx
 

More from John Paul Espino

Religion Education - Sa kabataang Pilipino - A La Juventud Filipina
Religion Education - Sa kabataang Pilipino - A La Juventud FilipinaReligion Education - Sa kabataang Pilipino - A La Juventud Filipina
Religion Education - Sa kabataang Pilipino - A La Juventud FilipinaJohn Paul Espino
 
Religion Education - Human Dignity - Freedom and Responsibility
Religion Education - Human Dignity - Freedom and ResponsibilityReligion Education - Human Dignity - Freedom and Responsibility
Religion Education - Human Dignity - Freedom and ResponsibilityJohn Paul Espino
 
Public Speaking and Leadership -Process of Reading
Public Speaking and Leadership -Process of ReadingPublic Speaking and Leadership -Process of Reading
Public Speaking and Leadership -Process of ReadingJohn Paul Espino
 
Environmental Engineering - Case Study - The Minamata Disease Disaster
Environmental Engineering - Case Study - The Minamata Disease DisasterEnvironmental Engineering - Case Study - The Minamata Disease Disaster
Environmental Engineering - Case Study - The Minamata Disease DisasterJohn Paul Espino
 
Computer Programming - if Statements & Relational Operators
Computer Programming - if Statements  & Relational OperatorsComputer Programming - if Statements  & Relational Operators
Computer Programming - if Statements & Relational OperatorsJohn Paul Espino
 
Philippine Constitution - Parliamentary Immunity
Philippine Constitution - Parliamentary Immunity Philippine Constitution - Parliamentary Immunity
Philippine Constitution - Parliamentary Immunity John Paul Espino
 
Philippine Constitution - Article XI - Accountability of Public Officers
Philippine Constitution - Article XI - Accountability of Public OfficersPhilippine Constitution - Article XI - Accountability of Public Officers
Philippine Constitution - Article XI - Accountability of Public OfficersJohn Paul Espino
 
Philippine Constitution - Article X - Local Government
Philippine Constitution - Article X - Local GovernmentPhilippine Constitution - Article X - Local Government
Philippine Constitution - Article X - Local GovernmentJohn Paul Espino
 
Philippine Constitution - Article VIII - Judicial Department
Philippine Constitution - Article VIII - Judicial DepartmentPhilippine Constitution - Article VIII - Judicial Department
Philippine Constitution - Article VIII - Judicial DepartmentJohn Paul Espino
 
Philippine Constitution - Article VII - Executive Department
Philippine Constitution - Article VII - Executive DepartmentPhilippine Constitution - Article VII - Executive Department
Philippine Constitution - Article VII - Executive DepartmentJohn Paul Espino
 
Philippine Constitution - Article VI - Legislative Power
Philippine Constitution - Article VI - Legislative PowerPhilippine Constitution - Article VI - Legislative Power
Philippine Constitution - Article VI - Legislative PowerJohn Paul Espino
 
Philippine Constitution - ARTICLE IX - Constitutional Commissions
Philippine Constitution - ARTICLE IX - Constitutional Commissions Philippine Constitution - ARTICLE IX - Constitutional Commissions
Philippine Constitution - ARTICLE IX - Constitutional Commissions John Paul Espino
 
Philosophy - the aesthetic attitude and the sublime
Philosophy - the aesthetic attitude and the sublime Philosophy - the aesthetic attitude and the sublime
Philosophy - the aesthetic attitude and the sublime John Paul Espino
 
Philosophy - the aestheic attidude and the sublime
Philosophy - the aestheic attidude and the sublimePhilosophy - the aestheic attidude and the sublime
Philosophy - the aestheic attidude and the sublimeJohn Paul Espino
 
Information literacy - effects of social networking to students thesis presen...
Information literacy - effects of social networking to students thesis presen...Information literacy - effects of social networking to students thesis presen...
Information literacy - effects of social networking to students thesis presen...John Paul Espino
 
Fundamentals of Accounting - Posting & Trial Balance
Fundamentals of Accounting - Posting & Trial BalanceFundamentals of Accounting - Posting & Trial Balance
Fundamentals of Accounting - Posting & Trial BalanceJohn Paul Espino
 
Fundamentals of accounting - manufacturing
Fundamentals of accounting - manufacturingFundamentals of accounting - manufacturing
Fundamentals of accounting - manufacturingJohn Paul Espino
 
Fundamentals of accounting - cost value profit (cvp)
Fundamentals of accounting - cost value profit (cvp)Fundamentals of accounting - cost value profit (cvp)
Fundamentals of accounting - cost value profit (cvp)John Paul Espino
 
Ethics - nicomachean ethics section 7 - 9
Ethics - nicomachean ethics section 7 - 9 Ethics - nicomachean ethics section 7 - 9
Ethics - nicomachean ethics section 7 - 9 John Paul Espino
 
Ethics - aristotle's ethics
Ethics - aristotle's ethicsEthics - aristotle's ethics
Ethics - aristotle's ethicsJohn Paul Espino
 

More from John Paul Espino (20)

Religion Education - Sa kabataang Pilipino - A La Juventud Filipina
Religion Education - Sa kabataang Pilipino - A La Juventud FilipinaReligion Education - Sa kabataang Pilipino - A La Juventud Filipina
Religion Education - Sa kabataang Pilipino - A La Juventud Filipina
 
Religion Education - Human Dignity - Freedom and Responsibility
Religion Education - Human Dignity - Freedom and ResponsibilityReligion Education - Human Dignity - Freedom and Responsibility
Religion Education - Human Dignity - Freedom and Responsibility
 
Public Speaking and Leadership -Process of Reading
Public Speaking and Leadership -Process of ReadingPublic Speaking and Leadership -Process of Reading
Public Speaking and Leadership -Process of Reading
 
Environmental Engineering - Case Study - The Minamata Disease Disaster
Environmental Engineering - Case Study - The Minamata Disease DisasterEnvironmental Engineering - Case Study - The Minamata Disease Disaster
Environmental Engineering - Case Study - The Minamata Disease Disaster
 
Computer Programming - if Statements & Relational Operators
Computer Programming - if Statements  & Relational OperatorsComputer Programming - if Statements  & Relational Operators
Computer Programming - if Statements & Relational Operators
 
Philippine Constitution - Parliamentary Immunity
Philippine Constitution - Parliamentary Immunity Philippine Constitution - Parliamentary Immunity
Philippine Constitution - Parliamentary Immunity
 
Philippine Constitution - Article XI - Accountability of Public Officers
Philippine Constitution - Article XI - Accountability of Public OfficersPhilippine Constitution - Article XI - Accountability of Public Officers
Philippine Constitution - Article XI - Accountability of Public Officers
 
Philippine Constitution - Article X - Local Government
Philippine Constitution - Article X - Local GovernmentPhilippine Constitution - Article X - Local Government
Philippine Constitution - Article X - Local Government
 
Philippine Constitution - Article VIII - Judicial Department
Philippine Constitution - Article VIII - Judicial DepartmentPhilippine Constitution - Article VIII - Judicial Department
Philippine Constitution - Article VIII - Judicial Department
 
Philippine Constitution - Article VII - Executive Department
Philippine Constitution - Article VII - Executive DepartmentPhilippine Constitution - Article VII - Executive Department
Philippine Constitution - Article VII - Executive Department
 
Philippine Constitution - Article VI - Legislative Power
Philippine Constitution - Article VI - Legislative PowerPhilippine Constitution - Article VI - Legislative Power
Philippine Constitution - Article VI - Legislative Power
 
Philippine Constitution - ARTICLE IX - Constitutional Commissions
Philippine Constitution - ARTICLE IX - Constitutional Commissions Philippine Constitution - ARTICLE IX - Constitutional Commissions
Philippine Constitution - ARTICLE IX - Constitutional Commissions
 
Philosophy - the aesthetic attitude and the sublime
Philosophy - the aesthetic attitude and the sublime Philosophy - the aesthetic attitude and the sublime
Philosophy - the aesthetic attitude and the sublime
 
Philosophy - the aestheic attidude and the sublime
Philosophy - the aestheic attidude and the sublimePhilosophy - the aestheic attidude and the sublime
Philosophy - the aestheic attidude and the sublime
 
Information literacy - effects of social networking to students thesis presen...
Information literacy - effects of social networking to students thesis presen...Information literacy - effects of social networking to students thesis presen...
Information literacy - effects of social networking to students thesis presen...
 
Fundamentals of Accounting - Posting & Trial Balance
Fundamentals of Accounting - Posting & Trial BalanceFundamentals of Accounting - Posting & Trial Balance
Fundamentals of Accounting - Posting & Trial Balance
 
Fundamentals of accounting - manufacturing
Fundamentals of accounting - manufacturingFundamentals of accounting - manufacturing
Fundamentals of accounting - manufacturing
 
Fundamentals of accounting - cost value profit (cvp)
Fundamentals of accounting - cost value profit (cvp)Fundamentals of accounting - cost value profit (cvp)
Fundamentals of accounting - cost value profit (cvp)
 
Ethics - nicomachean ethics section 7 - 9
Ethics - nicomachean ethics section 7 - 9 Ethics - nicomachean ethics section 7 - 9
Ethics - nicomachean ethics section 7 - 9
 
Ethics - aristotle's ethics
Ethics - aristotle's ethicsEthics - aristotle's ethics
Ethics - aristotle's ethics
 

Recently uploaded

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Recently uploaded (20)

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

Computer programming - variables constants operators expressions and statements

  • 1. VARIABLES, CONSTANTS, OPERATORS, EXPRESSIONS AND STATEMENTS By: John Paul Espino De La Salle University – Dasmarinas Facebook.com/Johnpaul.dss
  • 2.
  • 3. KEYWORDS • Reserved words that have a special meaning. • May not be redefined by the programmer.
  • 4. 32 KEYWORDS • auto • break • case • char • const • continue • default • do • double • else • enum • extern • float • for • goto • if • int • long • register • return • short • signed • sizeof • static • struct • switch • typedef • union • unsigned • void • volatile • while
  • 5. LITERALS • values that identifiers can hold. • Numeric literals – accepts numeric values • No comma • No space between unary sign and the digits • Must begin and end with a digit
  • 6. • Non-numeric literals - may be a character or sequence of characters • Example: ‘a’ ‘+’ ‘B’ “De La Salle University” “BCS”
  • 7. IDENTIFIERS • are the names that are used to reference variables, function labels and various user-defined objects.
  • 8. RULES FOR NAMING VALID IDENTIFIERS 1. An identifier in Turbo C can vary from 1 to 32 characters. 2. The first letter must be a letter or an underscore (_), followed optionally by sequence of letters, digits and/or underscore.
  • 9. RULES FOR NAMING VALID IDENTIFIERS 3. Turbo C also allows the $ to be used in an identifier name, but this is non-standard so it’s use is not recommended. 4. An identifier should not include embedded blanks. 5. You cannot use any of the Turbo C keyword as your variable or identifier name. 6. You should not call your variable by the same name as other functions.
  • 10. EXERCISES Identify the if the identifier is valid or invalid. 1. _ 2. a$ 3. Hello_World 4. _1 5. A 6. main 7. scanf 8. num1 9. tot sales 10. x-1 11. lname 12. Void Invalid: 2,3,6,7,9,10 Valid: 1,4,5,8,11,12
  • 11. integer1 45 integer2 72 sum 117 VARIABLES • are identifiers in C where we want to store values (data). Variables are important since they contain the values need for manipulation and evaluation. Variable names are stored in the computer’s memory.
  • 12. TYPE BITWIDTH RANGE char 8 0 to 255 int 16 -32768 to 32767 float 32 3.4E-32 to 3.4 E+38 double 64 1.7E-308 to 1.7 E+308 void 0 valueless DATA TYPES  type of data that a variable can hold
  • 13. TYPE EXAMPLES char ‘A’ ‘b’ ‘$’ ‘9’ ‘ab’‘10’ int 1 250 4500 float 3.5 42.56 345.6789 double 3.5647290… 486.145875... void valueless MORE ON DATA TYPES
  • 14. TYPE MODIFIERS  is used to alter the meaning of the base type to fit the needs of various situations more precisely.  The four type modifiers in C are: signed unsigned long short  Note:  Type modifiers can be applied to char and int except long which can also be applied to double
  • 15. TYPE BITWIDTH RANGE long int 32 -2147483648 to 2147483647 short int 16 -32768 to 32767 signed 32 -2147483648 to 2147483647 long int unsigned 32 0 to 4294967295 long int SOME COMBINATIONS OF C’S BASIC DATA TYPES AND MODIFIERS
  • 16. DECLARATION OF VARIABLES • All variables must be declared before they are used. • Syntax: type variable_list; • where: type is a valid data type variable_list is 1 or more identifier names with comma separator
  • 17. Local variables are variables that are declared inside a function. They are also called automatic variables. Local variables can only be referenced by statements that are inside the block in which the variables are declared. Example: #include <stdio.h> main () { int a,b,c; } Function block LOCAL VARIABLES
  • 18. Example: #include <stdio.h> int a,b,c; main () { } GLOBAL VARIABLES • variables are known throughout the entire program and may be used by any piece of code. Also, they will hold their values during the entire execution of the program. Global variables are created by declaring them outside any function.
  • 19. Example: #include <stdio.h> main () { int a,b,c; } Example: #include <stdio.h> int a,b,c; main () { } LOCAL VARIABLES GLOBAL VARIABLES
  • 20. Example: #include <stdio.h> main () { } test_function (int a, float b); { } FORMAL PARAMETERS • behave like local variables in a function. Their declaration occurs inside parentheses that follow the function name.
  • 21. CONSTANTS • Constants refer to fixed values that may not be altered by the program. • Turbo C supports one other type of constant in addition to those of the pre-defined data types. This is known as the string. All string constants are enclosed in double quote (“”). • Example: #define TEXT “Hello World” •
  • 22. DECLARATION OF CONSTANT • are identifiers that can store a value that cannot be changed during program execution. const type iden_name = value; where: type is a valid data type iden_name is a valid identifier value is a constant value of the identifier
  • 23. ASSIGNMENT STATEMENT Recall the assignment statement in flowcharting The general form of an assignment statement is var_name = expression where: var_name should be a variable, not a function or constant. expression may be a single constant or a complex combination of variables, operators and constants. Number = 5
  • 24. Examples: char ch = ‘a’; int first = 0; float num = 1.5; type var_name = constant You can give variables a value at the time they are declared by placing an equal sign (=) and a constant after the variable name. This is called initialization and it’s general form is: semicolon VARIABLE INITIALIZATION
  • 25. • Global variables are initialized at the start of the program • Local variables are initialized each time the block in which they are declared is entered • All global and local variables are initialized to zero (0) if no other initialization is specified. REMINDERS IN INITIALIZATION
  • 26. Variables of type const may not be changed during execution of the program. Variables of this type get value from initialization or by some hardware-dependent means. The modifier volatile is used to tell the compiler that a variable’s value can be changed in ways not explicitly specified by the program. ACCESS MODIFIERS
  • 27. REVIEW EXERCISES 1. Variables of type ___________are used to hold integer quantities. 2. Values of type character are used to hold ________characters or any 8-bit quantity. 3. __________in C are reserved words that have special meaning. 4. Values of type ________ and ________ are used to hold real numbers. 5. Real numbers have both an ________ and a fractional component. int ASCII Keywords float double integer
  • 28. 6. Identifiers are composed of ________, ________, and underscore. 7. Variables that are declared inside a function are called ______________. 8. _________ are identifiers that can store a value that cannot be changed. letters digits local variables Constants
  • 29. OPERATORS • Symbol that tells the compiler to perform specific mathematical or logical manipulations. • Classification • arithmetic operators • relational operators • logical operators
  • 30. A. ARITHMETIC OPERATORS - subtraction, unary minus +addition *multiplication / division % modulus division -- decrement ++ incrementNote: • When / is applied to an integer, any remainder is truncated • % cannot be used on type float or double
  • 31. B. RELATIONAL & LOGICAL OPERATORS • Relational Operators shows the relationship values have with one another. • Logical operators show the ways these relationships can be connected together using rules of formal logic.
  • 32. RELATIONAL OPERATORS Operator Action > greater than >= greater than or equal to < less than <= less than or equal to = = equal != not equal
  • 33. C. LOGICAL OPERATORS && AND || OR ! NOT
  • 34. EXPRESSION • Is any valid combination of operators, constants and variables that evaluates to a value.
  • 35. OPERATOR PRECEDENCE  ()  !, unary +, unary –  *, /, %  Binary +, binary –  <, <=, >, >=  ==, !=  &&  || highest lowest
  • 36. EVALUATE THE FOLLOWING: 1. Given: z = 5; a = 3, b = 9, w = 2, y = -5 Expression: z – a * b / 2 + w * y 2. Given: a = 5, b = 2, y = 3, c = 4, x = 1 Expression: (a * b + 2) * -y / ( c + x ) -18 7
  • 37. 3. Given: dei = 0; y = 4.0; z = 2.0; x = 3.0 Expression: !dei || ( y + z >= x – z ) 4. Given: x = 3; y = 2; j = 5; k = 3 Expression: (x-y) <= (j-k ==3) 1 0