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

Size: px
Start display at page:

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

Transcription

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

2 Objectives You will learn/review: In C, Java, and Python... Terminal input/output Data types, operators, statements Multi-file programs 2

3 "Circle" Programs Illustrate: Primitive data types Operators Terminal I/O 3

4 "Circle" in C See circle.c Data types: int, double Operators: =, *, +, cast Terminal input via scanf() Lack of exception handling Generalizing Must check function return value instead Data types, operators, and terminal I/O... 4

5 C Primitive Data Types Data Type Size Example Literals char 1 byte (char)-128, (char)127, 'a', '\n', '\t', '\0' unsigned char 1 byte (unsigned char) 0, (unsigned char)256 short 2 bytes? (short)-32768, (short)32767 unsigned short 2 bytes? (short)0, (short)65535 int 4 bytes? , unsigned int 4 bytes? 0U, U, 0123, 0x123 long 4 bytes? L, L unsigned long 4 bytes? 0UL, UL, 0123L, 0x123L float 4 bytes? F double 8 bytes? long double 12 bytes? L 5

6 C Operators Operator fun(params) a[i] s.f ps->f (type) *p, &x i++, ++i, i--, --i +x, -x (Precedence) Meaning (1) Function call (1) Array element selector (1) Structure field selector (1) Structure dereference and field selector (2) Typecast (2) Dereference, address of (2) Increment, decrement (2) Unary positive, unary negative ~i (2) Bitwise NOT!i (2) Logical NOT sizeof(type) (2) sizeof 6

7 C Operators Operator x*y, x/y, i%j x+y, x-y i<<j, i>>j x,y, x>y, x<=y, x>=y x==y, x!=y i&j i^j i j i&&j i j i?x:y (Precedence) Meaning (3) Multiplication, division, remainder (4) Addition, subtraction (5) Left-shift, right-shift (6) Relational (7) Relational (8) Bitwise AND (9) Bitwise EXCLUSIVE OR (10) Bitwise OR (11) Logical AND (12) Logical OR (13) Conditional expression 7

8 C Operators Operator x=y x+=y, x-=y, x*=y, x/=y i&=j, i^=j, i =j i<<=j, i>>=j x,y (Precedence) Meaning (14) Assignment (14) Assignment (14) Assignment (14) Assignment (15) Sequence 8

9 C Terminal I/O Reading from stdin: ivaluesread = scanf("%d", &i); ivaluesread = scanf("%lf", &d); s = fgets(s, size, stdin) 9

10 C Terminal I/O Writing to stdout: printf("%d", i); printf("%f", d); fputs(s, stdout); Writing to stderr: fprintf(stderr, "%d", i); fprintf(stderr, "%f", d); fputs(s, stderr); 10

11 "Circle" in Java See Circle.java Data types: int, double Operators: =, *, +, cast Terminal input via Scanner class Exception handling via try...catch statement Generalizing Data types, operators, and terminal I/O... 11

12 Java Primitive Data Types Data Type Size Example Literals boolean 1 bit false, true char 2 bytes '\u0000', 'uffff', 'a', '\n', '\t', '\0' byte 1 byte (byte)-128, (byte)127 short 2 bytes (short)-32768, (short)32767 int 4 bytes , long 8 bytes L, L float 4 bytes F double 8 bytes

13 Java Operators Operators method(params) a[i] obj.field, obj.method() class.field, class.method() i++, ++i, i--, --i +x, -x ~i,!b new Class() (type) x*y, x/y, i%j (Precedence) Meaning (1) Method call (1) Array element selector (1) Object member selector (1) Class member selector (2) Increment, decrement (2) Unary plus, unary minus (2) Bitwise NOT, logical NOT (3) Object creation (3) Typecast (4) Multiplication, division, remainder 13

14 Java Operators Operators x+y, x-y i<<j, i>>j, i>>>j x<y, x>y, x<=y, x>=y obj instanceof Class x==y, x!=y i&j i^j i j b1&&b2 b1 b2 (Precedence) Meaning (5) Addition, subtraction (6) Left shift, right shift, right shift zero fill (7) Relational (7) instanceof (8) relational (9) Bitwise AND (10) Bitwise exclusive OR (11) Bitwise OR (12) Logical AND (13) Logical OR 14

15 Java Operators Operators b?x:y x=y x+=y, x-=y, x*=y, x/=y, x%=y i&=j, i^=j, i =j i<<=j, i>>=j, i>>>=j (Precedence) Meaning (14) Conditional expression (15) Assignment (15) Assignment (15) Assignment (15) Assignment 15

16 Java Terminal I/O Reading from stdin: import java.util.scanner; Scanner scanner = new Scanner(System.in); int i = scanner.nextint(); double d = scanner.nextdouble(); String s = scanner.nextline(); 16

17 Java Terminal I/O Writing to stdout: System.out.print(i); System.out.println(d); System.out.println(s); Writing to stderr: System.err.print(i); System.err.println(d); System.err.println(s); 17

18 "Circle" in Python See circle.py Data types: number Type conversions via int() and float() functions String literals: ' ' or " " Operators: * (multiplication), % (string formatting) Terminal input via raw_input() Exception handling via try...except statement 18

19 "Circle" in Python Generalizing Conversion functions: int(obj), float(obj), str(obj), bool(obj) String formatting: conversion specifications are as in C Data types, operators, and terminal I/O... 19

20 Python Primitive Data Types Data Type Example Literals Integer numbers (plain or long) 1, 23, 3493, 01, 027, 06645, 0x1, 0x17, 0cDA5, 1L, 23L, L, 01L, 027L, L, 0x1L, 0x17L, 0x17486CBC75L (no theoretical size limit) Floating-point numbers 0., 0.0,.0, 1.0, 1e0, 1.0e0 (correspond to C doubles) Boolean False, True Null object None 20

21 Python Operators Operators (Priority) Meaning {key:expr,...} (1) Dictionary creation [expr,...] (2) List creation (expr,...) (3) Tuple creation, or just parentheses f(expr,...) (4) Function call x[startindex:stopindex] (5) Slicing (for sequences) x[index] (6) Indexing (for containers) x.attr (7) Attribute reference x**y (8) Exponentiation ~x (9) Bitwise NOT +x, -x (10) Unary plus, unary minus x*y, x/y, x//y, x%y (11) Mult, div, truncating div, remainder x+y, x-y (12) Addition, subtraction 21

22 Python Operators Operator x<<i, x>>i x&y x^y x y x<y, x<=y, x>y, x>=y x==y, x!=y x is y, x is not y x in y, x not in y not x x and y x or y (Priority) Meaning (13) Left-shift, right-shift (14) Bitwise AND (15) Bitwise XOR (16) Bitwise OR (17) Relational (17) Relational (18) Identity tests (19) Membership tests (20) Logical NOT (21) Logical AND (22) Logical OR 22

23 Python Terminal I/O Reading from stdin: str = raw_input() str = raw_input(promptstr) from sys import stdin str = stdin.readline() 23

24 Python Terminal I/O Writing to stdout: print str print str, Writing to stderr: print >>stderr, str print >>stderr, str, 24

25 "Euclid" Programs Illustrate: Control flow statements 25

26 "Euclid" in C See euclid.c Control flow statements: if, while, return Generalizing Statements... 26

27 C Statements Expression statement expr; Declaration statement modifiers datatype var [= expr] [, var [= expr]]...; Common modifiers: const, static Compound statement { statement; statement;...} 27

28 C Statements If statement if (intorptrexpr) statement [else statement] 0 or NULL pointer => false; anything else => true Switch statement switch (intexpr) { case (intvalue1): statement;...; break; case (intvalue2): statement;...; break;... default: statement;...; } 28

29 C Statements While statement while (intorptrexpr) statement; Do...while statement do statement while (intorptrexpr); For statement for (initexpr; intorptrexpr; increxpr) statement; 29

30 C Statements Break statement break; Continue statement continue; Return statement: return; return expr; 30

31 "Euclid" in Java See Euclid.java Control flow statements: if, while, return Generalizing Statements... 31

32 Java Statements Expression statement expr; Declaration statement modifiers datatype var [= expr] [, var [= expr]]...; Common modifiers: const, static Compound statement { statement; statement;...} 32

33 Java Statements If statement if (booleanexpr) statement else statement; Switch statement switch (intexpr) { case (intvalue1): statement;...; break; case (intvalue2): statement;...; break;... default: statement;...; } 33

34 Java Statements While statement while (booleanexpr)statement; Do...while statement do statement while (booleanexpr); For statement for (initexpr; booleanexpr; increxpr) statement; Foreach statement for (type var : IterableOrArrayObject) statement; 34

35 Java Statements Break statement break; Continue statement continue; Return statement return; return expr; 35

36 Java Statements Try...catch statement try { statement; statement; ; } catch (ExceptionType e) { statement; statement; ; } Throw statement throw object; 36

37 "Euclid" in Python See euclid.py Integer division operator Control flow statements: if, while, return, raise Weak typing Generalizing Statements... No type checks at compile-time, so... Must do type checks at run-time, or... Suffer the consequences!!! 37

38 Python Statements Assignment statements var = expr var += expr var -= expr var *= expr var /= expr var //= expr var %= expr var **= expr var &= expr var = expr var ^= expr var >>= expr var <<= expr 38

39 Python Statements Unpacking assignment statement var1,var2,... = iterable No-op statement pass Assert statement assert expr, message 39

40 Python Statements Print statement print expr,... print expr,..., hack Function call statement f(expr, name=expr,...) Return statement return return expr 40

41 Python Statements If statement if expr: statement(s) elif expr: statement(s) else: statement(s) False, 0, None, '', "", [], (), and {} indicate logical FALSE Any other value indicates logical TRUE 41

42 Python Statements While statement while expr: statement(s) False, 0, None, '', "", [], (), and {} indicate logical FALSE Any other value indicates logical TRUE 42

43 Python Statements For statements for var in range(startint, stopint): statements for var in range(stopint): statements for var in iterable: statements for key,value in mapping.iteritems(): statements Break statement break Continue statement continue 43

44 Python Statements Try...except statement try: statement(s) except [ExceptionType[, var]]: statement(s) Raise statement raise ExceptionType(str) 44

45 "IntMath" Modules Illustrate: Multi-file programs... Design to facilitate reuse of functions in multiple programs Module interfaces and implementations Building and running multi-file programs 45

46 "IntMath" in C See intmath.h, intmath.c, testintmath.c intmath.h is IntMath module interface Protection against multiple inclusion Function names begin with module name intmath.c is IntMath module implementation #includes intmath.h so compiler can enforce consistency testintmath.c is IntMath module client #includes intmath.h so compiler can check calls of IntMath_gcd() and IntMath_lcm() 46

47 "IntMath" in C Building: $ gcc -Wall -ansi -pedantic intmath.c testintmath.c -o testintmath Running: $ testintmath 47

48 "IntMath" in Java See IntMath.java, TestIntMath.java Module interface is not distinct from implementation IntMath.java is module interface and implementation Interface: public method headings & fields Implementation: all method headings & fields TestIntMath.java is IntMath module client 48

49 "IntMath" in Java Building and running $ javac TestIntMath.java Automatically builds IntMath.java Directory containing IntMath.java must be in CLASSPATH env var "." is in CLASSPATH by default $ java TestIntMath 49

50 "IntMath" in Python See intmath.py, testintmath.py Module interface is not distinct from implementation intmath.py is IntMath module interface and implementation testintmath.py is IntMath module client testintmath.py must import from intmath.py 50

51 "IntMath" in Python Building and running $ testintmath.py Automatically builds intmath.py Directory containing intmath.py must be in PYTHONPATH env var "." is in PYTHONPATH by default 51

52 "ReadNum" Modules The job: Prompt for and read an int/double from stdin Re-prompt and re-read if user enters bad data Illustrate Multi-file programs (as previous example) Unit testing 52

53 "ReadNum" in C See readnum.h, readnum.c, circle2.c Consumes entire line Otherwise bad characters would affect subsequent reads Calls strtol() and strtod() to convert string to int/double Contains lots of code for error handling 53

54 "ReadNum" in C Conditionally includes main() function in readnum module To build normally: Common technique for unit testing gcc -Wall -ansi -pedantic circle2.c readnum.c To build for unit testing: gcc -Wall -ansi -pedantic -D TEST_READNUM readnum.c

55 "ReadNum" in Java See ReadNum.java, Circle2.java Consumes entire line Otherwise bad characters would affect subsequent reads Calls Integer.parseInt() and Double.parseDouble() to convert String to int/double Uses exceptions to handle errors Defines main() method in ReadNum.java Common technique for unit testing 55

56 "ReadNum" in Python See readnum.py, circle2.py Consumes entire line Otherwise bad characters would affect subsequent reads Calls int() and float() to convert string to int/double Uses exceptions to handle errors Defines conditionally-executed test code in readnum.py Common technique for unit testing 56

57 Summary We have covered: In C, Java, and Python... Terminal input/output Data types, operators, statements Multi-file programs 57

Programming Languages Part 2. Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University

Programming Languages Part 2. Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University Programming Languages Part 2 Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University 1 Objectives You will learn/review: In Java and Python... Data types and operators Terminal input/output Statements

More information

Princeton University COS 333: Advanced Programming Techniques A Subset of C90

Princeton University COS 333: Advanced Programming Techniques A Subset of C90 Princeton University COS 333: Advanced Programming Techniques A Subset of C90 Program Structure /* Print "hello, world" to stdout. Return 0. */ { printf("hello, world\n"); -----------------------------------------------------------------------------------

More information

Princeton University COS 333: Advanced Programming Techniques A Subset of Python 2.7

Princeton University COS 333: Advanced Programming Techniques A Subset of Python 2.7 Princeton University COS 333: Advanced Programming Techniques A Subset of Python 2.7 Program Structure # Print "hello world" to stdout. print 'hello, world' # Print "hello world" to stdout. def f(): print

More information

Princeton University COS 333: Advanced Programming Techniques A Subset of Java

Princeton University COS 333: Advanced Programming Techniques A Subset of Java Princeton University COS 333: Advanced Programming Techniques A Subset of Java Program Structure public class Hello public static void main(string[] args) // Print "hello, world" to stdout. System.out.println("hello,

More information

Princeton University COS 333: Advanced Programming Techniques A Subset of PHP

Princeton University COS 333: Advanced Programming Techniques A Subset of PHP Princeton University COS 333: Advanced Programming Techniques A Subset of PHP Program Structure -----------------------------------------------------------------------------------

More information

SECTION II: LANGUAGE BASICS

SECTION II: LANGUAGE BASICS 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

More information

Continued from previous lecture

Continued from previous lecture The Design of C: A Rational Reconstruction: Part 2 Jennifer Rexford Continued from previous lecture 2 Agenda Data Types Statements What kinds of operators should C have? Should handle typical operations

More information

The Design of C: A Rational Reconstruction: Part 2

The Design of C: A Rational Reconstruction: Part 2 The Design of C: A Rational Reconstruction: Part 2 1 Continued from previous lecture 2 Agenda Data Types Operators Statements I/O Facilities 3 Operators Issue: What kinds of operators should C have? Thought

More information

JAC444 - Lecture 1. Introduction to Java Programming Language Segment 4. Jordan Anastasiade Java Programming Language Course

JAC444 - Lecture 1. Introduction to Java Programming Language Segment 4. Jordan Anastasiade Java Programming Language Course JAC444 - Lecture 1 Introduction to Java Programming Language Segment 4 1 Overview of the Java Language In this segment you will be learning about: Numeric Operators in Java Type Conversion If, For, While,

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

Informatics Ingeniería en Electrónica y Automática Industrial

Informatics Ingeniería en Electrónica y Automática Industrial Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical

More information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 3: Operators, Expressions and Type Conversion 101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

More information

Java for Python Programmers. Comparison of Python and Java Constructs Reading: L&C, App B

Java for Python Programmers. Comparison of Python and Java Constructs Reading: L&C, App B Java for Python Programmers Comparison of Python and Java Constructs Reading: L&C, App B 1 General Formatting Shebang #!/usr/bin/env python Comments # comments for human readers - not code statement #

More information

CSC 1214: Object-Oriented Programming

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:

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

Princeton University Computer Science 217: Introduction to Programming Systems The Design of C

Princeton University Computer Science 217: Introduction to Programming Systems The Design of C Princeton University Computer Science 217: Introduction to Programming Systems The Design of C C is quirky, flawed, and an enormous success. While accidents of history surely helped, it evidently satisfied

More information

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

More information

Fundamentals of Programming

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

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Expressions and Precedence. Last updated 12/10/18

Expressions and Precedence. Last updated 12/10/18 Expressions and Precedence Last updated 12/10/18 Expression: Sequence of Operators and Operands that reduce to a single value Simple and Complex Expressions Subject to Precedence and Associativity Six

More information

Operators and Expressions

Operators and Expressions Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL 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

More information

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y

More information

The Arithmetic Operators

The Arithmetic Operators The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x

More information

Java Basic Programming Constructs

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

More information

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

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

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE 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

More information

Computers Programming Course 6. Iulian Năstac

Computers Programming Course 6. Iulian Năstac Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap

More information

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

More information

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

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

More information

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>= Operators in java Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc. There are many types of operators in java which are given below: Unary Operator, Arithmetic

More information

Chapter 2. Elementary Programming

Chapter 2. Elementary Programming Chapter 2 Elementary Programming 1 Objectives To write Java programs to perform simple calculations To obtain input from the console using the Scanner class To use identifiers to name variables, constants,

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ OBJECT-ORIENTED PROGRAMMING IN JAVA 2 Programming

More information

A flow chart is a graphical or symbolic representation of a process.

A flow chart is a graphical or symbolic representation of a process. Q1. Define Algorithm with example? Answer:- A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of

More information

Writing Program in C Expressions and Control Structures (Selection Statements and Loops)

Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague

More information

Part I Part 1 Expressions

Part I Part 1 Expressions Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague

More information

Eng. Mohammed S. Abdualal

Eng. Mohammed S. Abdualal Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 3 Selections

More information

Reserved Words and Identifiers

Reserved Words and Identifiers 1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

Information Science 1

Information Science 1 Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting

More information

Lecture 02 C FUNDAMENTALS

Lecture 02 C FUNDAMENTALS Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void

More information

C Programming Language (Chapter 2 of K&R) Variables and Constants

C Programming Language (Chapter 2 of K&R) Variables and Constants C Programming Language (Chapter 2 of K&R) Types, Operators and Expressions Variables and Constants Basic objects manipulated by programs Declare before use: type var1, var2, int x, y, _X, x11, buffer;

More information

Operators in java Operator operands.

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,

More information

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands Performing Computations C provides operators that can be applied to calculate expressions: tax is 8.5% of the total sale expression: tax = 0.085 * totalsale Need to specify what operations are legal, how

More information

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

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL 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

More information

COMP6700/2140 Operators, Expressions, Statements

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,

More information

Prof. Navrati Saxena TA: Rochak Sachan

Prof. Navrati Saxena TA: Rochak Sachan JAVA Prof. Navrati Saxena TA: Rochak Sachan Operators Operator Arithmetic Relational Logical Bitwise 1. Arithmetic Operators are used in mathematical expressions. S.N. 0 Operator Result 1. + Addition 6.

More information

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one. http://www.tutorialspoint.com/go/go_operators.htm GO - OPERATORS Copyright tutorialspoint.com An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

More information

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below: Q1. Explain the structure of a C program Structure of the C program is shown below: Preprocessor Directives Global Declarations Int main (void) Local Declarations Statements Other functions as required

More information

Operators and Expressions:

Operators and Expressions: Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

And Parallelism. Parallelism in Prolog. OR Parallelism

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

More information

Lecture 3. More About C

Lecture 3. More About C Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants

More information

Programming in C++ 5. Integral data types

Programming in C++ 5. Integral data types Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long

More information

2. C99 standard guarantees uniqueness of characters for internal names. A. 12 B. 26 C. 31 D. 48

2. C99 standard guarantees uniqueness of characters for internal names. A. 12 B. 26 C. 31 D. 48 1. How can you make an infinite loop in C? A. while(1) { } B. loop:... goto loop; C. for(;;) { } D. All answers are right 2. C99 standard guarantees uniqueness of characters for internal names. A. 12 B.

More information

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CprE 288 Introduction to Embedded Systems Exam 1 Review.  1 CprE 288 Introduction to Embedded Systems Exam 1 Review http://class.ece.iastate.edu/cpre288 1 Overview of Today s Lecture Announcements Exam 1 Review http://class.ece.iastate.edu/cpre288 2 Announcements

More information

Chapter 2 Elementary Programming

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

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

More information

JAVA Programming Fundamentals

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

More information

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g. 1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object

More information

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Tools : The Java Compiler. The Java Interpreter. The Java Debugger Tools : The Java Compiler javac [ options ] filename.java... -depend: Causes recompilation of class files on which the source files given as command line arguments recursively depend. -O: Optimizes code,

More information

Goals of C "" The Goals of C (cont.) "" Goals of this Lecture"" The Design of C: A Rational Reconstruction"

Goals of C  The Goals of C (cont.)  Goals of this Lecture The Design of C: A Rational Reconstruction Goals of this Lecture The Design of C: A Rational Reconstruction Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C Why? Learning

More information

DM503 Programming B. Peter Schneider-Kamp.

DM503 Programming B. Peter Schneider-Kamp. DM503 Programming B Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm503/! VARIABLES, EXPRESSIONS & STATEMENTS 2 Values and Types Values = basic data objects 42 23.0 "Hello!" Types

More information

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9 Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits

More information

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz) SOFTWARE DEVELOPMENT 1 Operators 2018W (Institute of Pervasive Computing, JKU Linz) OPERATORS Operators are required to form expressions. Depending on the number of operands they take, they are called:

More information

Computer System and programming in C

Computer System and programming in C 1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

More information

Quick Reference Guide

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

More information

Introduction to Programming (Java) 2/12

Introduction to Programming (Java) 2/12 Introduction to Programming (Java) 2/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction

More information

TED Language Reference Manual

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

More information

CT 229. Java Syntax 26/09/2006 CT229

CT 229. Java Syntax 26/09/2006 CT229 CT 229 Java Syntax 26/09/2006 CT229 Lab Assignments Assignment Due Date: Oct 1 st Before submission make sure that the name of each.java file matches the name given in the assignment sheet!!!! Remember:

More information

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. 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:

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

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

More information

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

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

More information

File Handling in C. EECS 2031 Fall October 27, 2014

File Handling in C. EECS 2031 Fall October 27, 2014 File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically

More information

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types

More information

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

More information

A Java program contains at least one class definition.

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

More information

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages

More information

Chapter 2 Primitive Data Types and Operations. Objectives

Chapter 2 Primitive Data Types and Operations. Objectives Chapter 2 Primitive Data Types and Operations Prerequisites for Part I Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs,

More information

.Net Technologies. Components of.net Framework

.Net Technologies. Components of.net Framework .Net Technologies Components of.net Framework There are many articles are available in the web on this topic; I just want to add one more article over the web by explaining Components of.net Framework.

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All for repetition statement do while repetition statement switch multiple-selection statement break statement continue statement Logical

More information

STSCI Python Introduction. Class URL

STSCI Python Introduction. Class URL STSCI Python Introduction Class 2 Jim Hare Class URL www.pst.stsci.edu/~hare Each Class Presentation Homework suggestions Example files to download Links to sites by each class and in general I will try

More information

Operators in C. Staff Incharge: S.Sasirekha

Operators in C. Staff Incharge: S.Sasirekha Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C

More information

Primitive Data Types: Intro

Primitive Data Types: Intro Primitive Data Types: Intro Primitive data types represent single values and are built into a language Java primitive numeric data types: 1. Integral types (a) byte (b) int (c) short (d) long 2. Real types

More information

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled Interpreted vs Compiled Python 1 Java Interpreted Easy to run and test Quicker prototyping Program runs slower Compiled Execution time faster Virtual Machine compiled code portable Java Compile > javac

More information

Quick Reference Guide

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

More information

DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2. Jan Baumbach. DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net COURSE ORGANIZATION 2 Course Elements Lectures: 10 lectures Find schedule and class rooms in online

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II 1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

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

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

More information

Review for Test 1 (Chapter 1-5)

Review for Test 1 (Chapter 1-5) Review for Test 1 (Chapter 1-5) 1. Introduction to Computers, Programs, and Java a) What is a computer? b) What is a computer program? c) A bit is a binary digit 0 or 1. A byte is a sequence of 8 bits.

More information

C - Basics, Bitwise Operator. Zhaoguo Wang

C - Basics, Bitwise Operator. Zhaoguo Wang C - Basics, Bitwise Operator Zhaoguo Wang Java is the best language!!! NO! C is the best!!!! Languages C Java Python 1972 1995 2000 (2.0) Procedure Object oriented Procedure & object oriented Compiled

More information

COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP Primitive and Class Types. Yi Hong May 14, 2015 COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

More information

Lecture Set 4: More About Methods and More About Operators

Lecture Set 4: More About Methods and More About Operators 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

More information

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2 CONTENTS: Compilation Data and Expressions COMP 202 More on Chapter 2 Programming Language Levels There are many programming language levels: machine language assembly language high-level language Java,

More information