0% found this document useful (0 votes)
38 views48 pages

Lecture 05-06 (Literals, Variables, Operators, Dicision Making, Branching)

Uploaded by

Javeria Anwer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views48 pages

Lecture 05-06 (Literals, Variables, Operators, Dicision Making, Branching)

Uploaded by

Javeria Anwer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

CS-404 Visual Programming

Lecture 05 (Variables and Operators)


Course Teacher: Awais Mehmood, Department of Computer Science, UET, Taxila (Pakistan)
DEPARTMENT OF COMPUTER SCIENCE, UET TAXILA (PAKISTAN) 1
Goals for today

Operators
Data types in
Literals Variables and
C#.
Expressions.

DEPARTMENT OF COMPUTER SCIENCE, UET TAXILA (PAKISTAN) 2


Integer Literals

• Decimal, Octal, Hexadecimal, Binary


• (e.g., 101, 0134, 0X32FACE, 0b101)
C# Literals
C# Supports the following Floating-point Literals
literals:
• The literal with an integer part, a
decimal point, a fractional part, and
an exponent part.
• (e.g., 3.14145, 312569e-5, 784f)

DEPARTMENT OF COMPUTER SCIENCE, UET TAXILA (PAKISTAN) 4


▪ Character Literals
▪ Single quote, Unicode, and Escape Sequence
▪ (e.g., ‘a’, '\u0061’, '\n’)

C# Literals
-> Escape Sequence Examples are presented on
the next slide

DEPARTMENT OF COMPUTER SCIENCE, UET TAXILA (PAKISTAN) 5


Escape Sequence Meaning
\\ \ character
\’ ‘ character
\? ? character
\” ” character
\b Backspace
\a Alert or Bell
\n New Line
\f Form Feed
\r Carriage Return
\v Vertical Tab
\xhh… Hexadecimal number of one or more digits
DEPARTMENT OF COMPUTER SCIENCE, UET TAXILA (PAKISTAN) 6
String Literals
▪ Starts with Double quotes (“”) or @””
▪"Hello World!“ or @"Hello World!"
C# Literals
▪ Boolean Literals
▪ Only two values are allowed,
▪ i.e., true and false.

DEPARTMENT OF COMPUTER SCIENCE, UET TAXILA (PAKISTAN) 7


Examples
▪ 07778 // invalid: 8 is not an octal digit ▪ 304U // valid unsigned int literal
▪ 045uu // invalid: suffix (u) is repeated ▪ 3078L // valid long literal
▪ 0b105 // invalid: 5 is not a binary digit ▪ 965UL // valid unsigned long literal
▪ 0b101 // valid binary literal ▪ 3.14145 // Valid
▪ 456 // valid decimal literal ▪ 312569E-5 // Valid
▪ 02453 // valid octal literal ▪ 125E // invalid: Incomplete exponent
▪ 0x65d // valid hexadecimal literal ▪ 784f // valid
▪ 12356 // valid int literal ▪ .e45 // invalid: missing integer or fraction
DEPARTMENT OF COMPUTER SCIENCE, UET TAXILA (PAKISTAN) 8
Variables

9
Variables (contd.)

10
Datatypes

11
Datatypes (contd.)

12
Taxonomy C# datatypes

13
Declaration of variables

14
Default values

15
Default values (contd.)

16
Constant variables

17
Scope of variables

18
Scope of variables (contd.)

19
Boxing and Unboxing

20
Boxing

21
Boxing (contd.)

22
Unboxing

23
Types of operators

24
Arithmetic operators

25
Relational operators

26
Logical operators

27
Assignment Operator

28
Assignment Operator (contd.)

29
C# unary mathematical
operators

30
Prefix and postfix modes

31
Conditional operator

32
Operator precedence and parenthesis

33
Type conversion

34
Mathematical functions

35
CS-404 Visual Programming
Lecture 06 (Decision making and branching in C#)
Course Teacher: Awais Mehmood, Department of Computer Science, UET, Taxila (Pakistan)
DEPARTMENT OF COMPUTER SCIENCE, UET TAXILA (PAKISTAN) 36
Goals for
today
DECISION MAKING AND
BRANCHING IN C#

DEPARTMENT OF COMPUTER SCIENCE, UET TAXILA (PAKISTAN) 37


The if statement

38
Flowchart of simple if control

39
The IF-ELSE Statement

40
Flowchart of if-else control

41
Nesting of if-else statement

42
Flowchart of nested if-else statement

43
The Else-if ladder

44
The switch statement

45
46

Example
Fallthrough in switch
statement

47
Tasks (Assignment 1)

1 2 3
Write a program that Write a program that Write a program
counts total even & finds the largest that finds the grade
odd numbers stored among 3 numbers of a student using
in an array ‘number’. using nested if..else else if ladder.
statement.

DEPARTMENT OF COMPUTER SCIENCE, UET TAXILA (PAKISTAN) 48


Thank you
Ethics is knowing the difference between what you have a right to
do and what is right to do.
- Potter Stewart
DEPARTMENT OF COMPUTER SCIENCE, UET TAXILA (PAKISTAN) 49

You might also like