Computers Programming Course 6. Iulian Năstac

Similar documents
Computers Programming Course 5. Iulian Năstac

Computers Programming Course 7. Iulian Năstac

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

Expressions and Precedence. Last updated 12/10/18

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

OBJECT ORIENTED PROGRAMMING

Operators. Java operators are classified into three categories:

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

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

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:

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

Operators in C. Staff Incharge: S.Sasirekha

Information Science 1

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

UNIT- 3 Introduction to C++

JAVA OPERATORS GENERAL

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

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

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

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

UNIT 3 OPERATORS. [Marks- 12]

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

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

Operators & Expressions

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Basics of Programming

C-LANGUAGE CURRICULAM

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

Unit-2 (Operators) ANAND KR.SRIVASTAVA

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Operators and Expressions:

Arithmetic Operators. Portability: Printing Numbers

Unit 3. Operators. School of Science and Technology INTRODUCTION

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS

Programming for Engineers Iteration

Data Types and Variables in C language

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

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

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

Chapter 3: Operators, Expressions and Type Conversion

Programming in C++ 5. Integral data types

SECTION II: LANGUAGE BASICS

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

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

Department of Computer Science

Computer System and programming in C

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

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

The Arithmetic Operators

These are reserved words of the C language. For example int, float, if, else, for, while etc.

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

PERIYAR CENTENARY POLYTECHNIC COLLEGE Periyar Nagar- Vallam Thanjavur

Multiple Choice Questions ( 1 mark)

DEPARTMENT OF MATHS, MJ COLLEGE

Fundamental of Programming (C)

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

CSCI 171 Chapter Outlines

Review of the C Programming Language


Chapter 7. Expressions and Assignment Statements ISBN

Applied Computer Programming

Review of the C Programming Language for Principles of Operating Systems

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

Expression and Operator

Part I Part 1 Expressions

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

Operators in java Operator operands.

Reserved Words and Identifiers

C Programming Multiple. Choice

Introduction to C Language

Expressions & Assignment Statements

Continued from previous lecture

Fundamentals of Programming

Quick Reference Guide

Course Outline Introduction to C-Programming

CT 229. Java Syntax 26/09/2006 CT229

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Prof. Navrati Saxena TA: Rochak Sachan

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

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

Chapter 12 Variables and Operators

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

Infix to Postfix Conversion

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Operators and Type Conversion. By Avani M. Sakhapara Assistant Professor, IT Dept, KJSCE

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

ME 461 C review Session Fall 2009 S. Keres

I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub

Fundamental of C programming. - Ompal Singh

Operators. Lecture 3 COP 3014 Spring January 16, 2018

The Design of C: A Rational Reconstruction: Part 2

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

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

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


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

KARMAYOGI ENGINEERING COLLEGE, Shelve Pandharpur

Chapter 7. Expressions and Assignment Statements

Transcription:

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 Variables Variables are simply names used to refer to some location in memory. Types of variables: Local variables Global variables 3

Recap A more comprehensive classification Automatic variables variables which are allocated and deallocated automatically when program flow enters and leaves the variable's context An automatic variable is a variable defined inside a function block External variables variable defined outside any function block Static local variables variables that have been allocated statically whose lifetime extends across the entire run of the program Register variables register allocation is the process of assigning a large number of target program variables onto a small number of CPU registers 4

Recap Standard I/O routines are substitute for missing of I/O instructions C programming language provides many standard library functions for input and output. These functions make up the bulk of the C standard library header <stdio.h> (also in <conio.h> and <stdlib.h>) 5

synthesis Output functions printf puts putchar putch Input functions scanf gets getchar getch getche 6

Recap Expressions An expression in a programming language is a combination of explicit values, constants, variables, operators, and functions that are interpreted according to the particular rules of precedence and of association for a particular programming language, which computes and then produces another value. This process, like for mathematical expressions, is called evaluation. The value can be of various types, such as numerical, string, and logical. 7

Operators in C Programming languages typically support a set of operators, which differ in the calling of syntax and/or the argument passing mode from the language's functions. C programming language contains a fixed number of built-in operators. 8

1 () [] ->. :: Grouping, scope, array / member access 2! ~ - + * & sizeof type cast ++x - -x (most) unary operations, sizeof and type casts 3 * / % Multiplication, division, modulo 4 + - Addition and subtraction 5 << >> Bitwise shift left and right 6 < <= > >= Comparisons: less-than,... 7 ==!= Comparisons: equal and not equal 8 & Bitwise AND 9 ^ Bitwise exclusive OR 10 Bitwise inclusive (normal) OR 11 && Logical AND 12 Logical OR 13?: = += -= *= /= %= &= = ^= <<= >>= Conditional expression (ternary) and assignment operators 14, Comma operator 9

1. Brackets and data structure operators in C Associativity ( ) - Function call - Induce a priority in an expression [ ] - Array subscripting. Element selection by reference -> Element selection through pointer Left-to-right 10

2. Unary Operators Associativity ++ Suffix increment Left-to-right -- Suffix decrement ++ Prefix increment -- Prefix decrement Right-to-left + Unary plus - Unary minus! Logical NOT ~ Bitwise NOT (One's Complement) (type) Type cast * Indirection (dereference) & sizeof Address-of Size-of 11

3. Multiplication operators * Multiplication Associativity / Division Left-to-right % Modulo (remainder) 12

4. Additive operators Associativity + Addition Left-to-right - Subtraction 13

5. Shifting operators Associativity << Bitwise left shift Left-to-right >> Bitwise right shift Ex.: x = y << 2; assigns x the result of shifting y to the left by two bits. 14

Notes: << shift to the left (the left operand) with a number of binary positions indicated by the right operand >> shift to the right (the left operand) with a number of binary positions indicated by the right operand - The remaining bits become 0 - The left operand must be integer - The right operand is converted to integer 15

6. Relational operators Associativity < Less than Left-to-right <= Less than or equal to > Greater than >= Greater than or equal to 16

7. Equality operators Associativity == Equal to Left-to-right!= Not equal to 17

8. Logic bit operators Associativity & ^ Bitwise AND Bitwise XOR (exclusive or) Left-to-right Bitwise OR (inclusive or) 18

9. Logic operators Associativity && Logical AND Left-to-right Logical OR Left-to-right 19

10. Conditional operator In C programming,?... : is a ternary operator Format: condition? value_if_true : value_if_false The condition is evaluated true or false as a Boolean expression associativity: Right-to-Left Ex.: variable = condition? value_if_true : value_if_false ; The? : operator is similar, in a way, with conditional expressions (if-then-else constructs) 20

Note: One should ensures the right syntax of an expression that contains conditional operators. For example: E = ET1? (ET2? e1 : e2) : e3; is written in the right way, while E = ET1? e1 : ET2? e2 : e3; is confusing. 21

11. Assignment operators Associativity = += -= *= /= %= <<= >>= &= ^= = Direct assignment Assignment by sum Assignment by difference Assignment by product Assignment by quotient Assignment by remainder Assignment by bitwise left shift Assignment by bitwise right shift Assignment by bitwise AND Assignment by bitwise XOR Assignment by bitwise OR Right-to-left 22

12. Comma comma acts as separator between function parameters or variables associativity: Left-to-right Note that comma cannot be used in indexing multidimensional array Ex.: the code A[i, j] evaluates to A[j] with the i discarded, instead of the correct A[i][j] 23

The design of a program includes several steps description on natural language logic diagram source program compiling description on pseudocode linkediting executable program 24

Flow chart (logic diagram) A flow chart is a schematic representation of an algorithm or a process, or the step-bystep solution of a problem. Flow charts use suitably annotated geometric figures connected by flow lines for the purpose of designing or documenting a process or program. 25

A typical flowchart may have the following kinds of symbols: Start and Stop symbols - represented as circles, ovals or rounded (fillet) rectangles. Arrows - showing "flow of control". An arrow coming from one symbol and ending at another symbol represents that control passes to the symbol the arrow points to. Generic processing steps -represented as rectangles. Input/Output - represented as a parallelogram. Conditional or decision -represented as a diamond (rhombus) showing where a decision is necessary, commonly a Yes/No question or True/False test. etc. 26

Flowchart start / stop Flowchart process Flowchart connector Flowchart selection Flow line 27

28

29

Pseudocode Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm. No standard for pseudocode syntax exists, as a program in pseudocode is not an executable program. A programmer who needs to implement a specific algorithm, especially an unfamiliar one, will often start with a pseudocode description, and then "translate" that description into the target programming language and modify it to interact correctly with the rest of the program. 30

Pseudocode may vary widely in style Since, pseudocode generally does not actually obey the syntax rules of any particular language, there is no systematic standard form. Popular syntax sources include Pascal, BASIC, C, C++, Java, Lisp, and ALGOL. Variable declarations are typically omitted. 31

C style pseudo code void function fizzbuzz for (i = 1; i<=100; i++) { set print_number to true; if i is divisible by 3 print "Fizz ; set print_number to false; if i is divisible by 5 print "Buzz ; set print_number to false; if print_number, print i; print a newline; } 32

Instructions (Flow Control) There are several flow control statements in C programming language. Basically, C instructions can be organized as: Selection instructions Loop instructions Jump instructions Label instructions Expression instructions Block instructions 33