SlideShare a Scribd company logo
VARIABLES, CONSTANTS,
OPERATORS, EXPRESSIONS AND
STATEMENTS
By: John Paul Espino
De La Salle University – Dasmarinas
Facebook.com/Johnpaul.dss
Computer programming - variables constants operators expressions and statements
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
Ad

Recommended

OOP concepts -in-Python programming language
OOP concepts -in-Python programming language
SmritiSharma901052
 
1. importance of c
1. importance of c
Alamgir Hossain
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01
Wingston
 
Vb6.0 Introduction
Vb6.0 Introduction
Tennyson
 
Programming Fundamental Presentation
Programming Fundamental Presentation
fazli khaliq
 
Character Attribute in computer graphics
Character Attribute in computer graphics
HariTharshiniBscIT1
 
visual basic v6 introduction
visual basic v6 introduction
bloodyedge03
 
Programming flowcharts for C Language
Programming flowcharts for C Language
Aryan Ajmer
 
8 Array
8 Array
Kwan Lee
 
Basic elements of java
Basic elements of java
Ahmad Idrees
 
Clipping
Clipping
Mohd Arif
 
Procedural vs. object oriented programming
Procedural vs. object oriented programming
Haris Bin Zahid
 
Datatypes in python
Datatypes in python
eShikshak
 
Introduction to Algorithm
Introduction to Algorithm
ChristopherEsteban2
 
Presentation on C++ Programming Language
Presentation on C++ Programming Language
satvirsandhu9
 
Function overloading ppt
Function overloading ppt
Prof. Dr. K. Adisesha
 
Python programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptx
RaazIndia
 
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
Uttam Singh
 
Software Engineering
Software Engineering
UMA PARAMESWARI
 
Introduction to Object Oriented Programming
Introduction to Object Oriented Programming
Moutaz Haddara
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | Edureka
Edureka!
 
Abstract class in c++
Abstract class in c++
Sujan Mia
 
Algorithm and flowchart
Algorithm and flowchart
Elizabeth de Leon Aler
 
Identifiers
Identifiers
Then Murugeshwari
 
Dart ppt
Dart ppt
Krishna Teja
 
CSS L07 - Preparing the Installer
CSS L07 - Preparing the Installer
Marvin Bronoso
 
struct and class deferences
struct and class deferences
Naseer Khan Noor
 
Introduction to c
Introduction to c
Ajeet Kumar
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming Language
Zubayer Farazi
 

More Related Content

What's hot (20)

8 Array
8 Array
Kwan Lee
 
Basic elements of java
Basic elements of java
Ahmad Idrees
 
Clipping
Clipping
Mohd Arif
 
Procedural vs. object oriented programming
Procedural vs. object oriented programming
Haris Bin Zahid
 
Datatypes in python
Datatypes in python
eShikshak
 
Introduction to Algorithm
Introduction to Algorithm
ChristopherEsteban2
 
Presentation on C++ Programming Language
Presentation on C++ Programming Language
satvirsandhu9
 
Function overloading ppt
Function overloading ppt
Prof. Dr. K. Adisesha
 
Python programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptx
RaazIndia
 
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
Uttam Singh
 
Software Engineering
Software Engineering
UMA PARAMESWARI
 
Introduction to Object Oriented Programming
Introduction to Object Oriented Programming
Moutaz Haddara
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | Edureka
Edureka!
 
Abstract class in c++
Abstract class in c++
Sujan Mia
 
Algorithm and flowchart
Algorithm and flowchart
Elizabeth de Leon Aler
 
Identifiers
Identifiers
Then Murugeshwari
 
Dart ppt
Dart ppt
Krishna Teja
 
CSS L07 - Preparing the Installer
CSS L07 - Preparing the Installer
Marvin Bronoso
 
struct and class deferences
struct and class deferences
Naseer Khan Noor
 
Basic elements of java
Basic elements of java
Ahmad Idrees
 
Procedural vs. object oriented programming
Procedural vs. object oriented programming
Haris Bin Zahid
 
Datatypes in python
Datatypes in python
eShikshak
 
Presentation on C++ Programming Language
Presentation on C++ Programming Language
satvirsandhu9
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptx
RaazIndia
 
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
PROCEDURAL ORIENTED PROGRAMMING VS OBJECT ORIENTED PROGRAMING
Uttam Singh
 
Introduction to Object Oriented Programming
Introduction to Object Oriented Programming
Moutaz Haddara
 
Date and Time Module in Python | Edureka
Date and Time Module in Python | Edureka
Edureka!
 
Abstract class in c++
Abstract class in c++
Sujan Mia
 
CSS L07 - Preparing the Installer
CSS L07 - Preparing the Installer
Marvin Bronoso
 
struct and class deferences
struct and class deferences
Naseer Khan Noor
 

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

Introduction to c
Introduction to c
Ajeet Kumar
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming Language
Zubayer Farazi
 
Introduction to c
Introduction to c
sunila tharagaturi
 
Basic concept of c++
Basic concept of c++
shashikant pabari
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
RutviBaraiya
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
Dr.Florence Dayana
 
Ma3696 Lecture 3
Ma3696 Lecture 3
Brunel University
 
Fundamentals of computers - C Programming
Fundamentals of computers - C Programming
MSridhar18
 
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
dinesh620610
 
lecture2 (1).ppt variable s and operators
lecture2 (1).ppt variable s and operators
ChittyAvula
 
MODULE hdsfsf gefegsfs wfefwfwfg etegeg.pptx
MODULE hdsfsf gefegsfs wfefwfwfg etegeg.pptx
prasathg214
 
C programming language
C programming language
Abin Rimal
 
Escape Sequences and Variables
Escape Sequences and Variables
yarkhosh
 
C intro
C intro
SHIKHA GAUTAM
 
Lecture 1 .
Lecture 1 .
SwatiHans10
 
Chapter 2: Elementary Programming
Chapter 2: Elementary Programming
Eric Chou
 
C Language Part 1
C Language Part 1
Thapar Institute
 
c#.pptx
c#.pptx
JoselitoJMebolos
 
CP c++ programing project Unit 1 intro.pdf
CP c++ programing project Unit 1 intro.pdf
ShivamYadav886008
 
Introduction to c
Introduction to c
Ajeet Kumar
 
CSE 1201: Structured Programming Language
CSE 1201: Structured Programming Language
Zubayer Farazi
 
Esoft Metro Campus - Programming with C++
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
RutviBaraiya
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
Dr.Florence Dayana
 
Fundamentals of computers - C Programming
Fundamentals of computers - C Programming
MSridhar18
 
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
dinesh620610
 
lecture2 (1).ppt variable s and operators
lecture2 (1).ppt variable s and operators
ChittyAvula
 
MODULE hdsfsf gefegsfs wfefwfwfg etegeg.pptx
MODULE hdsfsf gefegsfs wfefwfwfg etegeg.pptx
prasathg214
 
C programming language
C programming language
Abin Rimal
 
Escape Sequences and Variables
Escape Sequences and Variables
yarkhosh
 
Chapter 2: Elementary Programming
Chapter 2: Elementary Programming
Eric Chou
 
CP c++ programing project Unit 1 intro.pdf
CP c++ programing project Unit 1 intro.pdf
ShivamYadav886008
 
Ad

More from John Paul Espino (20)

Religion Education - Sa kabataang Pilipino - A La Juventud Filipina
Religion Education - Sa kabataang Pilipino - A La Juventud Filipina
John Paul Espino
 
Religion Education - Human Dignity - Freedom and Responsibility
Religion Education - Human Dignity - Freedom and Responsibility
John Paul Espino
 
Public Speaking and Leadership -Process of Reading
Public Speaking and Leadership -Process of Reading
John Paul Espino
 
Environmental Engineering - Case Study - The Minamata Disease Disaster
Environmental Engineering - Case Study - The Minamata Disease Disaster
John Paul Espino
 
Computer Programming - if Statements & Relational Operators
Computer Programming - if Statements & Relational Operators
John Paul Espino
 
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 Officers
John Paul Espino
 
Philippine Constitution - Article X - Local Government
Philippine Constitution - Article X - Local Government
John Paul Espino
 
Philippine Constitution - Article VIII - Judicial Department
Philippine Constitution - Article VIII - Judicial Department
John Paul Espino
 
Philippine Constitution - Article VII - Executive Department
Philippine Constitution - Article VII - Executive Department
John Paul Espino
 
Philippine Constitution - Article VI - Legislative Power
Philippine Constitution - Article VI - Legislative Power
John Paul Espino
 
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
John Paul Espino
 
Philosophy - the aestheic attidude and the sublime
Philosophy - the aestheic attidude and the sublime
John Paul Espino
 
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 Balance
John Paul Espino
 
Fundamentals of accounting - manufacturing
Fundamentals of accounting - manufacturing
John Paul Espino
 
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
John Paul Espino
 
Ethics - aristotle's ethics
Ethics - aristotle's ethics
John Paul Espino
 
Religion Education - Sa kabataang Pilipino - A La Juventud Filipina
Religion Education - Sa kabataang Pilipino - A La Juventud Filipina
John Paul Espino
 
Religion Education - Human Dignity - Freedom and Responsibility
Religion Education - Human Dignity - Freedom and Responsibility
John Paul Espino
 
Public Speaking and Leadership -Process of Reading
Public Speaking and Leadership -Process of Reading
John Paul Espino
 
Environmental Engineering - Case Study - The Minamata Disease Disaster
Environmental Engineering - Case Study - The Minamata Disease Disaster
John Paul Espino
 
Computer Programming - if Statements & Relational Operators
Computer Programming - if Statements & Relational Operators
John Paul Espino
 
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 Officers
John Paul Espino
 
Philippine Constitution - Article X - Local Government
Philippine Constitution - Article X - Local Government
John Paul Espino
 
Philippine Constitution - Article VIII - Judicial Department
Philippine Constitution - Article VIII - Judicial Department
John Paul Espino
 
Philippine Constitution - Article VII - Executive Department
Philippine Constitution - Article VII - Executive Department
John Paul Espino
 
Philippine Constitution - Article VI - Legislative Power
Philippine Constitution - Article VI - Legislative Power
John Paul Espino
 
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
John Paul Espino
 
Philosophy - the aestheic attidude and the sublime
Philosophy - the aestheic attidude and the sublime
John Paul Espino
 
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 Balance
John Paul Espino
 
Fundamentals of accounting - manufacturing
Fundamentals of accounting - manufacturing
John Paul Espino
 
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
John Paul Espino
 
Ethics - aristotle's ethics
Ethics - aristotle's ethics
John Paul Espino
 
Ad

Recently uploaded (20)

vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 

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
  • 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