SlideShare a Scribd company logo
1 of 27
Data Types 
Lecture 2 
Dr. Hakem Beitollahi 
Computer Engineering Department 
Soran University
Objectives of this lecture 
 In this chapter you will learn: 
 Increment and Decrement (++ and --) 
 Assignment Operators 
 Basic data types in C# 
 Constant values 
 Conditional logical operators 
Data Types— 2
Main Mathematic Operations 
Operator Action 
+ Addition 
- Subtraction 
* Multiply 
/ Division 
% Reminder 
++ Increment 
-- Decrement 
Data Types— 3
Increment & decrement (I) 
 C/C++/C# includes two useful operators not found in some other 
computer languages. 
 These are the increment and decrement operators, ++ and - -  
 The operator ++ adds 1 to its operand, and − − subtracts 1. 
 i++ = i + 1 
 i-- = i - 1 
 Both the increment and decrement operators may either precede 
(prefix) or follow (postfix) the operand 
 i = i+1 can be written as i++ or ++i 
 i = i -1 can be written as i-- or --i 
 Please note: There is, however, a difference between the prefix and 
postfix forms when you use these operators in an expression 
Data Types— 4
Increment & decrement (II) 
// Increment and Decrement Operations ++/-- 
using System; 
class Comparison 
{ 
static void Main( string[] args ) 
{ 
int a = 10; 
int b = 10; 
int x, y; 
x = a++; 
y = ++b; 
Console.WriteLine("x = {0}, a ={1}.", x, a); 
Console.WriteLine("y = {0}, b ={1}.", y, b); 
}// end method Main 
} // end class Comparison 
x = 10 a = 11 
y = 11 b = 11 
Data Types— 5
Increment & decrement (III) 
// Increment and Decrement Operations ++/-- 
using System; 
class Comparison 
{ 
static void Main( string[] args ) 
{ 
int a = 10; 
int b = 10; 
Console.WriteLine(a++); 
Console.WriteLine(a); 
Console.WriteLine(++b); 
Console.WriteLine(b); 
}// end method Main 
} // end class Comparison 
10 
11 
11 
11 
Data Types— 6
Common Programming Error 1 
Attempting to use the increment or 
decrement operator on an expression 
other than a variable reference is a syntax 
error. A variable reference is a variable or 
expression that can appear on the left side 
of an assignment operation. For example, 
writing ++(x + 1) is a syntax error, 
because (x + 1) is not a variable 
reference 
Data Types — 7
Assignment Operator 
Data Types — 8
Assignment Operator (I) 
 C# provides several assignment operators for 
abbreviating assignment expressions. 
 Example: 
 c = c + 3; 
 c += 3; 
 where operator is one of the binary operators +, 
-, *, / or %, can be written in the form 
 variable operator= expression; 
Data Types — 9
Assignment Operator (II) 
Data Types — 10
Common Programming Error 1 
Placing a space character between symbols 
that compose an arithmetic assignment 
operator is a syntax error. 
A += 6; True A + = 6; False 
Data Types — 11
Basic Data Types in C# 
Data Types— 12
Basic data types in C# (I) 
 Programming languages store and 
process data in various ways depending 
on the type of the data; consequently, all 
data read, processed, or written by a 
program must have a type 
 A data type is used to 
 Identify the type of a variable when the 
variable is declared 
 Identify the type of the return value of a 
function (later) 
 Identify the type of a parameter expected by 
a function (later) 
Data Types— 13
Basic data types in C# (II) 
 There are 7 major data types in C++ 
 char e.g., ‘a’, ‘c’, ‘@’ 
 string e.g., “Zagros” 
 int e.g., 23, -12, 5, 0, 145678 
 float e.g., 54.65, -0.004, 65 
 double e.g., 54.65, -0.004, 65 
 bool only true and false 
 void no value 
Data Types— 14
Basic data types in C# (III) 
Type Range Size (bits) 
char U+0000 to U+ffff Unicode 16-bit character 
sbyte -128 to 127 Signed 8-bit integer 
byte 0 to 255 Unsigned 8-bit integer 
short -32,768 to 32,767 Signed 16-bit integer 
ushort 0 to 65535 Unsigned 16-bit integer 
int -2,147,483,648 to 2,147,483,647 Signed 32-bit integer 
uint 0 to 4,294,967,295 Unsigned 32-bit integer 
long -9,223,372,036,854,775,808 to 
9,223,372,036,854,775,807 
Signed 64-bit integer 
ulong 0 to 18,446,744,073,709,551,615 Unsigned 64-bit integer 
float -3.402823e38 .. 3.402823e38 Signed 32 bits 
double -1.79769313486232e308 .. 
1.79769313486232e308 
Signed 64 bits 
decimal -79228162514264337593543950335 .. 
79228162514264337593543950335 
Signed 128 bits 
Data Types— 15
Basic data types in C# (IV) 
 The general form of a declaration is 
 Type variable-list 
 Examples 
 int I, j, k; 
 char ch, a; 
 float f, balance; 
 double d; 
 bool decision; 
 string str; 
 Variables name 
Correct incorrect 
Count 3count 
test23 hi!there 
high_balance high...balance 
_name Test? 
@count co@nt 
 The first character must be a letter 
 -an underscore or @ 
 The subsequent characters must be either letters, digits, or 
underscores 
Data Types— 16
Constants in C# 
Data Types— 17
Const variables (I) 
 Variables of type const may not be changed by your 
program 
 The compiler is free to place variables of this type into 
read-only memory (ROM). 
 Example: 
 const int a = 10; 
Data Types— 18
// Constant learning 
using System; 
class Constant 
{ 
static void Main( string[] args ) 
{ 
const int c = 999; 
// c = 82; Error becuase c is constant and you cannot change it 
// c = 999; Error becuase c is constant and you cannot change it 
Console.WriteLine(c); 
}// end method Main 
} // end class Constant 
Data Types— 19
Conditional Logical operators 
Data Types— 20
Conditional Logical operators (I) 
 Conditional logical operators are useful when we want to 
test multiple conditions. 
 There are 3 types of conditional logical operators and 
they work the same way as the boolean AND, OR and 
NOT operators. 
 && - Logical AND 
 All the conditions must be true for the whole 
expression to be true. 
 Example: if (a == 10 && b == 9 && d == 1) 
means the if statement is only true when a == 10 and 
b == 9 and d == 1. 
Data Types— 21
expression1 expression2 expression1 && expression2 
false false false 
false true false 
true false false 
true true true 
Data Types— 22
Conditional Logical operators (II) 
 || - Conditional logical OR 
 The truth of one condition is enough to make 
the whole expression true. 
 Example: if (a == 10 || b == 9 || d == 1) 
means the if statement is true when either 
one of a, b or d has the right value. 
 ! – Conditional logical NOT (also called 
logical negation) 
 Reverse the meaning of a condition 
 Example: if (!(points > 90)) 
means if points not bigger than 90. 
Data Types— 23
expression1 expression2 expression1 || expression2 
false false false 
false true true 
true false true 
true true true 
Expression !expression 
false true 
true false 
Data Types— 24
Data Types — 25 
// Conditional logical operator 
using System; 
class Conditional_logical 
{ 
static void Main( string[] args ) 
{ 
int a = 10; 
int b = 15; 
if ((a == 10) && (b == 15)) 
Console.WriteLine("Apple"); 
else 
Console.WriteLine("Orange"); 
if ((a == 10) || (b == 15)) 
Console.WriteLine("Apple"); 
else 
Console.WriteLine("Orange"); 
if (!(a > 20)) 
Console.WriteLine("Apple"); 
else 
Console.WriteLine("Orange"); 
}// end method Main 
} // end class 
Apple 
Apple 
Apple
Operator preferences 
Operators Preferences 
() 1 
!,~,--,++ 2 
*,/,% 3 
+, - 4 
<, <=, >=, > 5 
==, != 6 
&& 7 
|| 8 
Note: in a+++a*a, the * has preference over ++ 
Note: in ++a+a*a, the ++ has preference over * 
Data Types— 26
Common Programming Error Tip 
Although 3 < x < 7 is a mathematically correct 
condition, it does not evaluate as you might expect in 
C#. Use ( 3 < x && x < 7 ) to get the proper 
evaluation in C#. 
Using operator == for assignment and using operator = 
for equality are logic errors. 
Use your text editor to search for all occurrences of = in 
your program and check that you have the correct 
assignment operator or logical operator in each place. 
Data Types— 27

More Related Content

What's hot (19)

CP Handout#3
CP Handout#3CP Handout#3
CP Handout#3
 
C++
C++C++
C++
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 
CP Handout#1
CP Handout#1CP Handout#1
CP Handout#1
 
CSharp Language Overview Part 1
CSharp Language Overview Part 1CSharp Language Overview Part 1
CSharp Language Overview Part 1
 
Getting started with c++.pptx
Getting started with c++.pptxGetting started with c++.pptx
Getting started with c++.pptx
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++
 
CP Handout#9
CP Handout#9CP Handout#9
CP Handout#9
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
C Token’s
C Token’sC Token’s
C Token’s
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
Cs211 module 1_2015
Cs211 module 1_2015Cs211 module 1_2015
Cs211 module 1_2015
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
Unit i intro-operators
Unit   i intro-operatorsUnit   i intro-operators
Unit i intro-operators
 

Viewers also liked

Bingham mc cutchen interview questions and answer
Bingham mc cutchen interview questions and answerBingham mc cutchen interview questions and answer
Bingham mc cutchen interview questions and answerJulianDraxler
 
Arabic Translation: نظام مكافحة التجسس الاستباقي بوصفه جزءاً من استمرارية الأ...
Arabic Translation: نظام مكافحة التجسس الاستباقي بوصفه جزءاً من استمرارية الأ...Arabic Translation: نظام مكافحة التجسس الاستباقي بوصفه جزءاً من استمرارية الأ...
Arabic Translation: نظام مكافحة التجسس الاستباقي بوصفه جزءاً من استمرارية الأ...Dr. Lydia Kostopoulos
 
Student organization president and vice president training
Student organization president and vice president trainingStudent organization president and vice president training
Student organization president and vice president trainingBelmontSELD
 
OSAC: Personal Digital Security Presentation
OSAC: Personal Digital Security PresentationOSAC: Personal Digital Security Presentation
OSAC: Personal Digital Security PresentationDr. Lydia Kostopoulos
 
Pengukuran aliran a.(differential)
Pengukuran aliran a.(differential)Pengukuran aliran a.(differential)
Pengukuran aliran a.(differential)Frenki Niken
 
Manual de Arborizacao Urbana
Manual de Arborizacao UrbanaManual de Arborizacao Urbana
Manual de Arborizacao UrbanaAline Naue
 
"How to Sell Electric Vehicles to Canadians," Cara Clairman, Plug n' Drive
"How to Sell Electric Vehicles to Canadians," Cara Clairman, Plug n' Drive"How to Sell Electric Vehicles to Canadians," Cara Clairman, Plug n' Drive
"How to Sell Electric Vehicles to Canadians," Cara Clairman, Plug n' DriveClean Energy Canada
 
Anti inflammatory agents
Anti inflammatory agentsAnti inflammatory agents
Anti inflammatory agentsnawal al-matary
 
Math Project for Mr. Medina's Class
Math Project for Mr. Medina's ClassMath Project for Mr. Medina's Class
Math Project for Mr. Medina's Classsmit5008
 
Dental arts davis square
Dental arts davis squareDental arts davis square
Dental arts davis squareDr. Paul Dobrin
 
Cyber Espionage and Insider Threat: House of Commons Panel Discussion
Cyber Espionage and Insider Threat: House of Commons Panel DiscussionCyber Espionage and Insider Threat: House of Commons Panel Discussion
Cyber Espionage and Insider Threat: House of Commons Panel DiscussionDr. Lydia Kostopoulos
 
Proactive Counterespionage as a Part of Business Continuity and Resiliency
Proactive Counterespionage as a Part of Business Continuity and ResiliencyProactive Counterespionage as a Part of Business Continuity and Resiliency
Proactive Counterespionage as a Part of Business Continuity and ResiliencyDr. Lydia Kostopoulos
 

Viewers also liked (19)

British food
British foodBritish food
British food
 
Administrative
AdministrativeAdministrative
Administrative
 
Bingham mc cutchen interview questions and answer
Bingham mc cutchen interview questions and answerBingham mc cutchen interview questions and answer
Bingham mc cutchen interview questions and answer
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
 
Arabic Translation: نظام مكافحة التجسس الاستباقي بوصفه جزءاً من استمرارية الأ...
Arabic Translation: نظام مكافحة التجسس الاستباقي بوصفه جزءاً من استمرارية الأ...Arabic Translation: نظام مكافحة التجسس الاستباقي بوصفه جزءاً من استمرارية الأ...
Arabic Translation: نظام مكافحة التجسس الاستباقي بوصفه جزءاً من استمرارية الأ...
 
інтернет і соц. сеті
інтернет і соц. сетіінтернет і соц. сеті
інтернет і соц. сеті
 
Student organization president and vice president training
Student organization president and vice president trainingStudent organization president and vice president training
Student organization president and vice president training
 
OSAC: Personal Digital Security Presentation
OSAC: Personal Digital Security PresentationOSAC: Personal Digital Security Presentation
OSAC: Personal Digital Security Presentation
 
Pengukuran aliran a.(differential)
Pengukuran aliran a.(differential)Pengukuran aliran a.(differential)
Pengukuran aliran a.(differential)
 
Who says 'everything's alright' (3)
Who says 'everything's alright'  (3)Who says 'everything's alright'  (3)
Who says 'everything's alright' (3)
 
Manual de Arborizacao Urbana
Manual de Arborizacao UrbanaManual de Arborizacao Urbana
Manual de Arborizacao Urbana
 
"How to Sell Electric Vehicles to Canadians," Cara Clairman, Plug n' Drive
"How to Sell Electric Vehicles to Canadians," Cara Clairman, Plug n' Drive"How to Sell Electric Vehicles to Canadians," Cara Clairman, Plug n' Drive
"How to Sell Electric Vehicles to Canadians," Cara Clairman, Plug n' Drive
 
Tagmax_ebooklet
Tagmax_ebookletTagmax_ebooklet
Tagmax_ebooklet
 
Anti inflammatory agents
Anti inflammatory agentsAnti inflammatory agents
Anti inflammatory agents
 
Math Project for Mr. Medina's Class
Math Project for Mr. Medina's ClassMath Project for Mr. Medina's Class
Math Project for Mr. Medina's Class
 
Dental arts davis square
Dental arts davis squareDental arts davis square
Dental arts davis square
 
огюст роден
огюст роденогюст роден
огюст роден
 
Cyber Espionage and Insider Threat: House of Commons Panel Discussion
Cyber Espionage and Insider Threat: House of Commons Panel DiscussionCyber Espionage and Insider Threat: House of Commons Panel Discussion
Cyber Espionage and Insider Threat: House of Commons Panel Discussion
 
Proactive Counterespionage as a Part of Business Continuity and Resiliency
Proactive Counterespionage as a Part of Business Continuity and ResiliencyProactive Counterespionage as a Part of Business Continuity and Resiliency
Proactive Counterespionage as a Part of Business Continuity and Resiliency
 

Similar to Lecture 2

the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxAnkitaVerma776806
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2Don Dooley
 
B.sc CSIT 2nd semester C++ Unit2
B.sc CSIT  2nd semester C++ Unit2B.sc CSIT  2nd semester C++ Unit2
B.sc CSIT 2nd semester C++ Unit2Tekendra Nath Yogi
 
C programming session 02
C programming session 02C programming session 02
C programming session 02Dushmanta Nath
 
presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxKrishanPalSingh39
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptxrinkugupta37
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressionsStoian Kirov
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteachingeteaching
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshopBAINIDA
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxKrishanPalSingh39
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01Abdul Samee
 

Similar to Lecture 2 (20)

the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
C program
C programC program
C program
 
B.sc CSIT 2nd semester C++ Unit2
B.sc CSIT  2nd semester C++ Unit2B.sc CSIT  2nd semester C++ Unit2
B.sc CSIT 2nd semester C++ Unit2
 
What is c
What is cWhat is c
What is c
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptx
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
C tutorial
C tutorialC tutorial
C tutorial
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptx
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressions
 
additional.pptx
additional.pptxadditional.pptx
additional.pptx
 
C tutorial
C tutorialC tutorial
C tutorial
 
C material
C materialC material
C material
 
Programming in C
Programming in CProgramming in C
Programming in C
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 
C++ lecture 01
C++   lecture 01C++   lecture 01
C++ lecture 01
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptx
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
 

More from Soran University (6)

Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 

Recently uploaded

Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 

Recently uploaded (20)

(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 

Lecture 2

  • 1. Data Types Lecture 2 Dr. Hakem Beitollahi Computer Engineering Department Soran University
  • 2. Objectives of this lecture  In this chapter you will learn:  Increment and Decrement (++ and --)  Assignment Operators  Basic data types in C#  Constant values  Conditional logical operators Data Types— 2
  • 3. Main Mathematic Operations Operator Action + Addition - Subtraction * Multiply / Division % Reminder ++ Increment -- Decrement Data Types— 3
  • 4. Increment & decrement (I)  C/C++/C# includes two useful operators not found in some other computer languages.  These are the increment and decrement operators, ++ and - -  The operator ++ adds 1 to its operand, and − − subtracts 1.  i++ = i + 1  i-- = i - 1  Both the increment and decrement operators may either precede (prefix) or follow (postfix) the operand  i = i+1 can be written as i++ or ++i  i = i -1 can be written as i-- or --i  Please note: There is, however, a difference between the prefix and postfix forms when you use these operators in an expression Data Types— 4
  • 5. Increment & decrement (II) // Increment and Decrement Operations ++/-- using System; class Comparison { static void Main( string[] args ) { int a = 10; int b = 10; int x, y; x = a++; y = ++b; Console.WriteLine("x = {0}, a ={1}.", x, a); Console.WriteLine("y = {0}, b ={1}.", y, b); }// end method Main } // end class Comparison x = 10 a = 11 y = 11 b = 11 Data Types— 5
  • 6. Increment & decrement (III) // Increment and Decrement Operations ++/-- using System; class Comparison { static void Main( string[] args ) { int a = 10; int b = 10; Console.WriteLine(a++); Console.WriteLine(a); Console.WriteLine(++b); Console.WriteLine(b); }// end method Main } // end class Comparison 10 11 11 11 Data Types— 6
  • 7. Common Programming Error 1 Attempting to use the increment or decrement operator on an expression other than a variable reference is a syntax error. A variable reference is a variable or expression that can appear on the left side of an assignment operation. For example, writing ++(x + 1) is a syntax error, because (x + 1) is not a variable reference Data Types — 7
  • 9. Assignment Operator (I)  C# provides several assignment operators for abbreviating assignment expressions.  Example:  c = c + 3;  c += 3;  where operator is one of the binary operators +, -, *, / or %, can be written in the form  variable operator= expression; Data Types — 9
  • 10. Assignment Operator (II) Data Types — 10
  • 11. Common Programming Error 1 Placing a space character between symbols that compose an arithmetic assignment operator is a syntax error. A += 6; True A + = 6; False Data Types — 11
  • 12. Basic Data Types in C# Data Types— 12
  • 13. Basic data types in C# (I)  Programming languages store and process data in various ways depending on the type of the data; consequently, all data read, processed, or written by a program must have a type  A data type is used to  Identify the type of a variable when the variable is declared  Identify the type of the return value of a function (later)  Identify the type of a parameter expected by a function (later) Data Types— 13
  • 14. Basic data types in C# (II)  There are 7 major data types in C++  char e.g., ‘a’, ‘c’, ‘@’  string e.g., “Zagros”  int e.g., 23, -12, 5, 0, 145678  float e.g., 54.65, -0.004, 65  double e.g., 54.65, -0.004, 65  bool only true and false  void no value Data Types— 14
  • 15. Basic data types in C# (III) Type Range Size (bits) char U+0000 to U+ffff Unicode 16-bit character sbyte -128 to 127 Signed 8-bit integer byte 0 to 255 Unsigned 8-bit integer short -32,768 to 32,767 Signed 16-bit integer ushort 0 to 65535 Unsigned 16-bit integer int -2,147,483,648 to 2,147,483,647 Signed 32-bit integer uint 0 to 4,294,967,295 Unsigned 32-bit integer long -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 Signed 64-bit integer ulong 0 to 18,446,744,073,709,551,615 Unsigned 64-bit integer float -3.402823e38 .. 3.402823e38 Signed 32 bits double -1.79769313486232e308 .. 1.79769313486232e308 Signed 64 bits decimal -79228162514264337593543950335 .. 79228162514264337593543950335 Signed 128 bits Data Types— 15
  • 16. Basic data types in C# (IV)  The general form of a declaration is  Type variable-list  Examples  int I, j, k;  char ch, a;  float f, balance;  double d;  bool decision;  string str;  Variables name Correct incorrect Count 3count test23 hi!there high_balance high...balance _name Test? @count co@nt  The first character must be a letter  -an underscore or @  The subsequent characters must be either letters, digits, or underscores Data Types— 16
  • 17. Constants in C# Data Types— 17
  • 18. Const variables (I)  Variables of type const may not be changed by your program  The compiler is free to place variables of this type into read-only memory (ROM).  Example:  const int a = 10; Data Types— 18
  • 19. // Constant learning using System; class Constant { static void Main( string[] args ) { const int c = 999; // c = 82; Error becuase c is constant and you cannot change it // c = 999; Error becuase c is constant and you cannot change it Console.WriteLine(c); }// end method Main } // end class Constant Data Types— 19
  • 20. Conditional Logical operators Data Types— 20
  • 21. Conditional Logical operators (I)  Conditional logical operators are useful when we want to test multiple conditions.  There are 3 types of conditional logical operators and they work the same way as the boolean AND, OR and NOT operators.  && - Logical AND  All the conditions must be true for the whole expression to be true.  Example: if (a == 10 && b == 9 && d == 1) means the if statement is only true when a == 10 and b == 9 and d == 1. Data Types— 21
  • 22. expression1 expression2 expression1 && expression2 false false false false true false true false false true true true Data Types— 22
  • 23. Conditional Logical operators (II)  || - Conditional logical OR  The truth of one condition is enough to make the whole expression true.  Example: if (a == 10 || b == 9 || d == 1) means the if statement is true when either one of a, b or d has the right value.  ! – Conditional logical NOT (also called logical negation)  Reverse the meaning of a condition  Example: if (!(points > 90)) means if points not bigger than 90. Data Types— 23
  • 24. expression1 expression2 expression1 || expression2 false false false false true true true false true true true true Expression !expression false true true false Data Types— 24
  • 25. Data Types — 25 // Conditional logical operator using System; class Conditional_logical { static void Main( string[] args ) { int a = 10; int b = 15; if ((a == 10) && (b == 15)) Console.WriteLine("Apple"); else Console.WriteLine("Orange"); if ((a == 10) || (b == 15)) Console.WriteLine("Apple"); else Console.WriteLine("Orange"); if (!(a > 20)) Console.WriteLine("Apple"); else Console.WriteLine("Orange"); }// end method Main } // end class Apple Apple Apple
  • 26. Operator preferences Operators Preferences () 1 !,~,--,++ 2 *,/,% 3 +, - 4 <, <=, >=, > 5 ==, != 6 && 7 || 8 Note: in a+++a*a, the * has preference over ++ Note: in ++a+a*a, the ++ has preference over * Data Types— 26
  • 27. Common Programming Error Tip Although 3 < x < 7 is a mathematically correct condition, it does not evaluate as you might expect in C#. Use ( 3 < x && x < 7 ) to get the proper evaluation in C#. Using operator == for assignment and using operator = for equality are logic errors. Use your text editor to search for all occurrences of = in your program and check that you have the correct assignment operator or logical operator in each place. Data Types— 27