# SECTION II: LANGUAGE BASICS

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators are an important part of any programming language and their function is simple i.e. they allow manipulating data. Operators are special symbols or keywords used to designate mathematical operations or some other types of operation that are performed on one or more values called operands. Operators are indispensable components of Java. Java provides around 40 different operators. Operators are used for simple purposes such as: Assigning values to variables Working with strings Working with numbers Controlling program flow And so on

2 82 Core Java For Beginners Operators in Java, fall into the following different categories: Assignment Arithmetic Relational Logical Bitwise Compound assignment Conditional Type Whilst exploring operators in Java, it's also prudent to know which operators have the highest precedence. Precedence determines in which order operators execute. The operators in the following table are listed according to precedence order: Operators Precedence Postfix expr++ expr-- Unary ++expr --expr +expr -expr ~! Multiplication * / % Additive + - Shift << >> >>> Relational < > <= >= instanceof Equality ==!= Bitwise AND & Bitwise Exclusive OR ^ Bitwise Inclusive OR Logical AND && Logical OR Ternary? : Assignment = += -= *= /= %= &= ^= = <<= >>= >>>= From the above table, it is clear that the operator Postfix has the highest precedence. Operators with higher precedence are evaluated before operators with relatively lower precedence. Operators on the same line have equal precedence. When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first.

3 Operators 83 All binary operators except for the assignment operators are evaluated from left to right and the assignment operators are evaluated right to left. Properties Of Operators In Java, an expression carries out some operation(s) that are directed by a list of allowed operators. An operator acts upon one, two or three operands. The following are some general properties of operators: Operands An operand can be: A numeric variable i.e. integer, floating point or character Any primitive type variable i.e. numeric and boolean Reference variable to an object A literal i.e. numeric value, boolean value or string An array element i.e. "a[2]" Char primitive, which in numeric operations is treated as an unsigned two byte integer The operator is: Unary, if it acts on a single operand Binary, if it requires two operands The conditional operator is the only ternary operator in Java. A unary operator may appear before [prefix] its argument or after [postfix] its argument, whereas, a binary or ternary operator appears between its arguments. Returned Value After an operation completes, a value is returned. The following example uses the assignment operator = and the addition operator +.

4 84 Core Java For Beginners Explanation: The above example results into: x holding the value 3 y holding the value 8 [3+5] The assignment operator = in the statement returns the value of y i.e. 8. The following example uses the above statement y=x+5 in another expression. Explanation: The above example results into: y holding the value 8 z holding the value 32 The assignment operator = in the statement y=x+5 produces a new value for y and returns the value of y to be used in the expression for z. Arithmetic Operators There are five operators used to accomplish basic arithmetic in Java. Arithmetic Operators that Java provides are addition, subtraction, multiplication and division, which are very similar to the counterparts in basic mathematics. The only additional symbol that looks new is %, which divides one operand by another and returns the remainder as its result.

5 Operators 85 The following are the arithmetic operators: Operator Meaning Result + Addition x=3 x Subtraction x=3 5-x 2 * Multiplication x=5 x*5 25 / Division 20/2 7/ % Modulus 5%3 7%2 20%2 The arithmetic operators can be combined with the simple assignment operator to create compound assignments. The following example shows how the value of x is incremented by Alternatively: The + operator can also be used for concatenating/joining two strings together.

6 86 Core Java For Beginners This program using the assignment operator, makes appropriate string assignments to the first two variables and then using + concatenates the two values, assigns the concatenated value to a third variable which now contains "Welcome to Sharanam Shah website." and finally outputs the concatenated value.

7 Operators 87 Assignment Operators Variables were invented with an objective to hold something, which is usually data. That's where the assignment operator comes in. To fill a variable with data, an assignment operator such as = [equal] symbol can be used. Assignment operator enables writing a value to a variable. The first operand [the one on the left of the assignment operator] must be a variable. The value of an assignment is the final value assigned to the variable. This operator can be used to assign strings, integers even the results of functions Syntax: Explanation: In the above code spec: The variable var is assigned the value 5 The variable str is assigned the value Sharanam Shah The variable fn is assigned the value returned by the function MyFunction() The following table displays the expressions and its meaning: Operators Expression Meaning = x=y x=y += x += y x = x + y -= x -= y x = x y *= x *= y x = x * y /= x /= y x = x / y %= x %= y x = x % y

8 88 Core Java For Beginners Increment and Decrement There are operators which are unique i.e. they operate only on variables and not on any value. The reason for this is that in addition to calculating the result value, the value of the variable itself changes as well. These special operators are called increment and decrement operators. The increment operator is ++ and the decrement operator is --. These operators are placed immediately after or immediately before a variable name. Increment and decrement operators are called prefix and postfix operators.

9 The following table shows the increment and decrement examples: Operators 89 Description Result Value of the Variable var++ Post increment var is incremented by 1 The previous value of var ++var Pre increment var is incremented by 1 The new value of var (incremented value) var-- Post decrement var is decremented by 1 The previous value of var --var Pre decrement var is decremented by 1 The new value of var (decremented value) Consider the following example. Explanation: In the above code spec: The variable x is given the value 42 The variable y is given the variable x's value i.e. 42 before it is incremented and then the value of x is increment to 43

10 90 Core Java For Beginners This is the example of post-increment. Here, the assignment takes place first and increment takes place latter. Hence the value of y is 42. The value of x is incremented to 44 and then the value of z is given the variable x's value This is the example of pre-increment. Here, the increment takes place first and assignment takes place next. Hence, the value of z is 44 and not 43. Relational Operators Java has several operators, known as relational operators, which are used when making comparisons between variables and any other type of information in the program. A relational operator compares two values and determines the relationship between them. All relational operators are binary operators and their operands are numeric expressions. Binary numeric promotion is applied to the operands of these operators. These operators are used in expressions that returns Boolean values of true or false, depending on whether the comparison being made is true or not. Relational operators have precedence lower than arithmetic operators, but higher than that of the assignment operators. The following table shows a list of comparison operators: Operator Meaning Returns = = Equal 3 == 9 False!= Not equal 3!= 9 True < Less than 3 < 9 True > Greater than 15 > 18 False <= Less than or equal to 3 <= 9 True >= Greater than or equal to 15 >= 18 False

11 Operators 91 Logical Operators Expressions that result in Boolean values such as relation operators can be combined to form more complex expressions. This is handled through logical operators. These operators are used for the logical combination AND, OR and the logical NOT. Operator Meaning Description Returns && AND When two Boolean expressions are linked by the (A && B) False && operators, the combined expression returns a true only if both the Boolean expressions is true. OR When two Boolean expressions are linked by the (A B) True operators, the combined expression returns a true, if either of the Boolean expressions is true.! NOT It reverses the value of a Boolean expression the!(a && B) True same way that a minus symbol reverses the positive or negative sign on a number.

12 92 Core Java For Beginners Bitwise Operator Java provides Bit wise operators to manipulate the contents of variables at the bit level. Bitwise operators perform an operation on the bitwise representation of their arguments. Unless the arguments are strings, they are converted to their corresponding integer representation and the operation is then performed. These variables must be of numeric data type such as char, short, int or long. The following table displays the bitwise operators: Operator Meaning Description & Bitwise AND Compares all the bits in operand one against all the bits on operand two and returns a result with all the joint bits set., or, Bitwise OR Compares all the bits in operand one against those in operand two and returns a result with all the bits set in either of them. ^ Bitwise XOR Compares all the bits in operand one against those in operand (Exclusive OR) two and returns a result with all the bits set in either of them but not both. ~ Unary Bitwise Compliment Flip each bit making every zeros a one and every one a zero. For example, a byte contains 8 bits, applying this operator to a value whose bit pattern is would change to << Signed Left Shifts a bit to the left. High order bits lost. Zero bits fill in right Shift bits. >> Signed Right Shifts a bit to the right. Low order bits lost. Same bits value as Shift sign fills in the left bits. Zero for positive numbers and 1 for negative numbers. >>> Unsigned Right Shift Shifts a zero into the leftmost position while the leftmost position after >> depends on sign extension.

13 Operators 93 Conditional Operator The conditional operator? : can be thought of as shorthand for an if-then-else statement. This operator is also known as the ternary operator because it uses three operands. It is the only ternary operator in Java.

14 94 Core Java For Beginners The operator evaluates the first argument and, if true, evaluates the second argument. If the first argument evaluates to false, then the third argument is evaluated. Syntax: The instance Of Operator The instanceof operator is used for object reference variables. It checks whether an object is of a particular type. The instanceof operator is used to test if an object is an instance of a class, an instance of a subclass or an instance of a class that implements a particular interface. Syntax:

15 Operators 95 If the object referred by the variable on the left side of the operator passes the IS-A check for the class/interface type on the right side then the result is true. [Parent.java] [Child.java]

16 96 Core Java For Beginners [MainClass.java] Since this file is dependent on other.java files such as Parent.java and Child.java all of these are automatically compiled. HINT When using the instanceof operator, keep in mind that NULL is not an instance of anything. The Book CDROM holds the complete application source code for the following applications: Codespecs \ Section 2 \ Chapter05_Cds \ ConcatString.java Codespecs \ Section 2 \ Chapter05_Cds \ ArithmeticOperator.java Codespecs \ Section 2 \ Chapter05_Cds \ AssignmentOperator.java Codespecs \ Section 2 \ Chapter05_Cds \ IncrementDecrement.java Codespecs \ Section 2 \ Chapter05_Cds \ RelationalOperator.java Codespecs \ Section 2 \ Chapter05_Cds \ LogicalOperator.java Codespecs \ Section 2 \ Chapter05_Cds \ BitwiseOperator.java Codespecs \ Section 2 \ Chapter05_Cds \ InstanceOfOperator.java Codespecs \ Section 2 \ Chapter05_Cds \ Parent.java Codespecs \ Section 2 \ Chapter05_Cds \ Child.java

17 Operators 97 Codespecs \ Section 2 \ Chapter05_Cds \ MainClass.java The application can be directly used by compiling and executing it.

18

### Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

Sir Muhammad Naveed Arslan Ahmed Shaad (1163135 ) Muhammad Bilal ( 1163122 ) www.techo786.wordpress.com CHAPTER: 2 NOTES:- VARIABLES AND OPERATORS The given Questions can also be attempted as Long Questions.

### Operators in java Operator operands.

Operators in java Operator in java is a symbol that is used to perform operations and the objects of operation are referred as operands. There are many types of operators in java such as unary operator,

### Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following g roups:

JAVA BASIC OPERATORS http://www.tuto rialspo int.co m/java/java_basic_o perato rs.htm Copyrig ht tutorialspoint.com Java provides a rich set of operators to manipulate variables. We can divide all the

### Operators & Expressions

Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.

### CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

### Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

### COMP6700/2140 Operators, Expressions, Statements

COMP6700/2140 Operators, Expressions, Statements Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU 3 March 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Operators,

### JAVA Programming Fundamentals

Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

### Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

### Fundamentals of Programming

Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

### Unit-2 (Operators) ANAND KR.SRIVASTAVA

Unit-2 (Operators) ANAND KR.SRIVASTAVA 1 Operators in C ( use of operators in C ) Operators are the symbol, to perform some operation ( calculation, manipulation). Set of Operations are used in completion

### Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void

### ISA 563 : Fundamentals of Systems Programming

ISA 563 : Fundamentals of Systems Programming Variables, Primitive Types, Operators, and Expressions September 4 th 2008 Outline Define Expressions Discuss how to represent data in a program variable name

### 4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.

### Java Basic Programming Constructs

Java Basic Programming Constructs /* * This is your first java program. */ class HelloWorld{ public static void main(string[] args){ System.out.println( Hello World! ); A Closer Look at HelloWorld 2 This

### ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators ARITHMATIC OPERATORS The assignment operator in IDL is the equals sign, =. IDL uses all the familiar arithmetic operators

### CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

### Chapter 12 Variables and Operators

Chapter 12 Variables and Operators Highlights (1) r. height width operator area = 3.14 * r *r + width * height literal/constant variable expression (assignment) statement 12-2 Highlights (2) r. height

### RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators:

http://www.tutorialspoint.com/ruby/ruby_operators.htm RUBY OPERATORS Copyright tutorialspoint.com Ruby supports a rich set of operators, as you'd expect from a modern language. Most operators are actually

### More Programming Constructs -- Introduction

More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and

### In Delphi script, when values are assigned to variables, the colon-equal operator is used; :=

Statements and Operators Old Content - visit altium.com/documentation Modified by on 13-Sep-2017 Parent page: DelphiScript DelphiScript Statements A statement in DelphiScript is considered as simple when

### Object-Oriented Programming. Topic 2: Fundamental Programming Structures in Java

Electrical and Computer Engineering Object-Oriented Topic 2: Fundamental Structures in Java Maj Joel Young Joel.Young@afit.edu 8-Sep-03 Maj Joel Young Java Identifiers Identifiers Used to name local variables

### Java Primer 1: Types, Classes and Operators

Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

### Course Outline Introduction to C-Programming

ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,

### Client-Side Web Technologies. JavaScript Part I

Client-Side Web Technologies JavaScript Part I JavaScript First appeared in 1996 in Netscape Navigator Main purpose was to handle input validation that was currently being done server-side Now a powerful

### Logical and Bitwise Expressions

Logical and Bitwise Expressions The truth value will set you free. 1 Expression Constant Variable Unary Operator Binary Operator (expression) Function Invocation Assignment: = Prefix: +, -, ++, --,!, ~

### Program Fundamentals

Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

### Chapter 7. Expressions and Assignment Statements ISBN

Chapter 7 Expressions and Assignment Statements ISBN 0-321-33025-0 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit

### A First Program - Greeting.cpp

C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout

### Operators. Lecture 3 COP 3014 Spring January 16, 2018

Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special built-in symbols that have functionality, and work on operands operand an input to an operator Arity - how many operands an operator

### Quick Reference Guide

SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD mikroelektronika Development tools - Books - Compilers Quick Reference Quick Reference Guide with EXAMPLES for Pascal language This reference guide

### Operators. Java Primer Operators-1 Scott MacKenzie = 2. (b) (a)

Operators Representing and storing primitive data types is, of course, essential for any computer language. But, so, too, is the ability to perform operations on data. Java supports a comprehensive set

### LAB A Translating Data to Binary

LAB A Translating Data to Binary Create a directory for this lab and perform in it the following groups of tasks: LabA1.java 1. Write the Java app LabA1 that takes an int via a command-line argument args[0]

### Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

Lecture 2: Variables and Operators AITI Nigeria Summer 2012 University of Lagos. Agenda Variables Types Naming Assignment Data Types Type casting Operators Declaring Variables in Java type name; Variables

### Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN

Chapter 7 Expressions and Assignment Statements (updated edition 11) ISBN 0-321-49362-1 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean

### Chapter 7. Expressions and Assignment Statements

Chapter 7 Expressions and Assignment Statements Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment

### 4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.

### CSE I-Sem)

Objective: Understanding miscellaneous aspects of C ENUMERATED, STRUCTURE AND UNION TYPES: Derived types- structures declaration, definition and initialization of structures, accessing structures, nested

### Chapter 3 Structure of a C Program

Chapter 3 Structure of a C Program Objectives To be able to list and describe the six expression categories To understand the rules of precedence and associativity in evaluating expressions To understand

### Programming Languages: Part 2. Robert M. Dondero, Ph.D. Princeton University

Programming Languages: Part 2 Robert M. Dondero, Ph.D. Princeton University 1 Objectives You will learn/review: In C, Java, and Python... Terminal input/output Data types, operators, statements Multi-file

### Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

### Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations

### L-System Fractal Generator: Language Reference Manual

L-System Fractal Generator: Language Reference Manual Michael Eng, Jervis Muindi, Timothy Sun Contents 1 Program Definition 3 2 Lexical Conventions 3 2.1 Comments...............................................

### Programming in C++ 6. Floating point data types

Programming in C++ 6. Floating point data types! Introduction! Type double! Type float! Changing types! Type promotion & conversion! Casts! Initialization! Assignment operators! Summary 1 Introduction

### Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program

### Operators And Expressions

Operators And Expressions Operators Arithmetic Operators Relational and Logical Operators Special Operators Arithmetic Operators Operator Action Subtraction, also unary minus + Addition * Multiplication

### C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

### Why embedded systems?

MSP430 Intro Why embedded systems? Big bang-for-the-buck by adding some intelligence to systems. Embedded Systems are ubiquitous. Embedded Systems more common as prices drop, and power decreases. Which

### JAVASCRIPT - OPERATORS

JAVASCRIPT - OPERATORS http://www.tutorialspoint.com/javascript/javascript_operators.htm Copyright tutorialspoint.com What is an operator? Let us take a simple expression 4 + 5 is equal to 9. Here 4 and

Assoc. Prof. Dr. Marenglen Biba Before writing a program to solve a problem, have a thorough understanding of the problem and a carefully planned approach to solving it. Understand the types of building

### Module 2 Introducing Data Types and Operators

Module 2 Introducing Data Types and Operators Table of Contents CRITICAL SKILL 2.1: The C++ Data Types... 2 Project 2-1 Talking to Mars... 10 CRITICAL SKILL 2.2: Literals... 12 CRITICAL SKILL 2.3: A Closer

### Arithmetic and Bitwise Operations on Binary Data

Arithmetic and Bitwise Operations on Binary Data CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant & O Hallaron s slides 1 Boolean Algebra Developed by

### CS 253. January 14, 2017

CS 253 Department of Computer Science College of Engineering Boise State University January 14, 2017 1/30 Motivation Most programming tasks can be implemented using abstractions (e.g. representing data

### Values and Variables 1 / 30

Values and Variables 1 / 30 Values 2 / 30 Computing Computing is any purposeful activity that marries the representation of some dynamic domain with the representation of some dynamic machine that provides

### C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 By the end of this lecture, you will be able to identify the

### Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Assignment Lecture 9 Logical Operations Formatted Print Printf Increment and decrement Read through 3.9, 3.10 Read 4.1. 4.2, 4.3 Go through checkpoint exercise 4.1 Logical Operations - Motivation Logical

### C Language Summary. Chris J Michael 28 August CSC 4103 Operating Systems Fall 2008 Lecture 2 C Summary

Chris J Michael cmicha1@lsu.edu 28 August 2008 C Language Summary Heavily Influenced by the GNU C Reference Manual: http://www.gnu.org/software/gnu-c-manual/ Introduction -C98, or the original ANSI C standard

### CT 229 Java Syntax Continued

CT 229 Java Syntax Continued 29/09/2006 CT229 Lab Assignments One Week Extension for Lab Assignment 1. Due Date: Oct 8 th Before submission make sure that the name of each.java file matches the name given

### Variables and literals

Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of

### C++ is case sensitive language, meaning that the variable first_value, First_Value or FIRST_VALUE will be treated as different.

C++ Character Set a-z, A-Z, 0-9, and underscore ( _ ) C++ is case sensitive language, meaning that the variable first_value, First_Value or FIRST_VALUE will be treated as different. Identifier and Keywords:

### The Warhol Language Reference Manual

The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming

### Data Conversion & Scanner Class

Data Conversion & Scanner Class Quick review of last lecture August 29, 2007 ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor: Alexander Stoytchev Numeric Primitive Data Storing

### 3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

3. EXPRESSIONS It is a sequence of operands and operators that reduce to a single value. Operator : It is a symbolic token that represents an action to be taken. Ex: * is an multiplication operator. Operand:

### Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

Lecture 02 Summary C/Java Syntax Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 1 2 By the end of this lecture, you will be able to identify the

### COMP 122/L Lecture 2. Kyle Dewey

COMP 122/L Lecture 2 Kyle Dewey Outline Operations on binary values AND, OR, XOR, NOT Bit shifting (left, two forms of right) Addition Subtraction Twos complement Bitwise Operations Bitwise AND Similar

### TED Language Reference Manual

1 TED Language Reference Manual Theodore Ahlfeld(twa2108), Konstantin Itskov(koi2104) Matthew Haigh(mlh2196), Gideon Mendels(gm2597) Preface 1. Lexical Elements 1.1 Identifiers 1.2 Keywords 1.3 Constants

### C: How to Program. Week /Mar/05

1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

### CPSC 319. Week 2 Java Basics. Xiaoyang Liu & Sorting Algorithms

CPSC 319 Week 2 Java Basics Xiaoyang Liu xiaoyali@ucalgary.ca & Sorting Algorithms Java Basics Variable Declarations Type Size Range boolean 1 bit true, false char 16 bits Unicode characters byte 8 bits

### Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

### 14:332:231 DIGITAL LOGIC DESIGN. Hardware Description Languages

14:332:231 DIGITAL LOGIC DESIGN Ivan Marsic, Rutgers University Electrical & Computer Engineering Fall 2013 Lecture #22: Introduction to Verilog Hardware Description Languages Basic idea: Language constructs

### Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

### Applied Computer Programming

Applied Computer Programming Representation of Numbers. Bitwise Operators Course 07 Lect.eng. Adriana ALBU, PhD Politehnica University Timisoara Internal representation All data, of any type, processed

### C expressions. (Reek, Ch. 5) 1 CS 3090: Safety Critical Programming in C

C expressions (Reek, Ch. 5) 1 Shift operations Left shift: value > n Two definitions: logical version: discard the n

### Homework #3 CS2255 Fall 2012

Homework #3 CS2255 Fall 2012 MULTIPLE CHOICE 1. The, also known as the address operator, returns the memory address of a variable. a. asterisk ( * ) b. ampersand ( & ) c. percent sign (%) d. exclamation

### Numerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2

Numerical Computing in C and C++ Jamie Griffin Semester A 2017 Lecture 2 Visual Studio in QM PC rooms Microsoft Visual Studio Community 2015. Bancroft Building 1.15a; Queen s W207, EB7; Engineering W128.D.

### 9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

Outline Expression Evaluation and Control Flow In Text: Chapter 6 Notation Operator evaluation order Operand evaluation order Overloaded operators Type conversions Short-circuit evaluation of conditions

### Data types Expressions Variables Assignment. COMP1400 Week 2

Data types Expressions Variables Assignment COMP1400 Week 2 Data types Data come in different types. The type of a piece of data describes: What the data means. What we can do with it. Primitive types

### Lecture 2 Tao Wang 1

Lecture 2 Tao Wang 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common programming errors

### And Parallelism. Parallelism in Prolog. OR Parallelism

Parallelism in Prolog And Parallelism One reason that Prolog is of interest to computer scientists is that its search mechanism lends itself to parallel evaluation. In fact, it supports two different kinds

### Lecture 3 Tao Wang 1

Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers

### Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

### Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators, Expressions, Statements and Arrays. Java technology is: A programming

Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

### Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

### Embedded Systems. Introduction. The C Language. Introduction. Why C instead ASM. Introduction to C Embedded Programming language

Introduction Embedded Systems Introduction to C Embedded Programming language Why C instead ASM 1. C is a high level language, it is easier to write and read than assembly codes. 2. You don't have to think

### Lesson 3: Basic Programming Concepts

3 ICT Gaming Essentials Lesson 3: Basic Programming Concepts LESSON SKILLS After completing this lesson, you will be able to: Explain the types and uses of variables and operators in game programming.

### C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic

### Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total. Name: ID: Problem 1) (8 points) For the following code segment, what are the values of i, j, k, and d, after the segment

### Basics of Java: Expressions & Statements. Nathaniel Osgood CMPT 858 February 15, 2011

Basics of Java: Expressions & Statements Nathaniel Osgood CMPT 858 February 15, 2011 Java as a Formal Language Java supports many constructs that serve different functions Class & Interface declarations

### In Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability. programs into their various phases.

Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 2: Sentinel-Controlled Repetition In Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability.

### Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9

### Perl: Arithmetic, Operator Precedence and other operators. Perl has five basic kinds of arithmetic:

Perl: Arithmetic, Operator Precedence and other operators Robert A. Fulkerson College of Information Science and Technology http://www.ist.unomaha.edu/ University of Nebraska at Omaha http://www.unomaha.edu/

### Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical

### Computer Programming CS F111

Computer Programming CS F111 BITS Pilani Dubai Campus NAND KUMAR Basics of C Programming BITS Pilani Dubai Campus Write a program that 1. Asks 5 marks from the user, find the average of the marks and print

### JAVASCRIPT. sarojpandey.com.np/iroz. JavaScript

JAVASCRIPT 1 Introduction JAVASCRIPT is a compact, object-based scripting language for developing client Internet applications. was designed to add interactivity to HTML pages. is a scripting language