Constants and Variables

Similar documents
Department of Computer Science

Data Types and Variables in C language

Operators in java Operator operands.

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

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

Operators in C. Staff Incharge: S.Sasirekha

Operators & Expressions

UNIT 3 OPERATORS. [Marks- 12]

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

Operators. Java operators are classified into three categories:

Unit-2 (Operators) ANAND KR.SRIVASTAVA

Unit 3. Operators. School of Science and Technology INTRODUCTION

JAVA OPERATORS GENERAL

Prepared by: Shraddha Modi

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

Chapter 3: Operators, Expressions and Type Conversion

Operators and Expressions:

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

Prof. Navrati Saxena TA: Rochak Sachan

SECTION II: LANGUAGE BASICS

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

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

The Arithmetic Operators

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

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

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

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

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

Making Science Graphs and Interpreting Data

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

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

Chapter 4: Basic C Operators

Infix to Postfix Conversion

Review of the C Programming Language for Principles of Operating Systems

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

Reserved Words and Identifiers

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

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

Basics of Programming

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

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

Fundamentals of Programming CS-110. Lecture 3

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

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Expressions and Statementst t. Assignment Operator. C Programming Lecture 6 : Operators. Expression

Chapter 4 Expression & Operators

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Language Reference Manual simplicity

Arithmetic Operators. Portability: Printing Numbers

Operators and Expressions

Declaration and Memory

UNIT- 3 Introduction to C++

Lecture 3 Operators MIT AITI

Java Primer 1: Types, Classes and Operators

PESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities

Programming in C++ 5. Integral data types

Computer Programming CS F111

Review of the C Programming Language

Chapter 7. Additional Control Structures

CSCE 110 PROGRAMMING FUNDAMENTALS

Lecture 3. More About C

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

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Assignment: 1. (Unit-1 Flowchart and Algorithm)

Java enum, casts, and others (Select portions of Chapters 4 & 5)

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

Part I Part 1 Expressions

Data types, variables, constants

Expressions and Precedence. Last updated 12/10/18

Programming. Elementary Concepts

Operators And Expressions

Chapter 2 Working with Data Types and Operators

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

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

LECTURE 17. Expressions and Assignment

CS313D: ADVANCED PROGRAMMING LANGUAGE

More Programming Constructs -- Introduction

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities

Programming with Java

Yacoub Sabatin Muntaser Abulafi Omar Qaraeen. Introduction

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data Structures & Algorithm Analysis. Lecturer: Souad Alonazi

CSC 1214: Object-Oriented Programming

Test 1. CSC 121 Lecture Lecturer: Howard Rosenthal. March 4, 2014

ME 461 C review Session Fall 2009 S. Keres

Full file at

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

Information Science 1

BASIC ELEMENTS OF A COMPUTER PROGRAM

Introduction. Problem Solving on Computer. Data Structures (collection of data and relationships) Algorithms

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

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

Internet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved.

CHW 469 : Embedded Systems

Advantages of writing algorithm

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

Chapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved.

Lecture 02 C FUNDAMENTALS

Transcription:

DATA STORAGE

Constants and Variables In many introductory courses you will come across characteristics or elements such as rates, outputs, income, etc., measured by numerical values. Some of these will always remain the same, and some will change. The characteristic or element that remains the same is called a constant. For example, the number of donuts in a dozen is always 12. That means the number of donuts in a dozen is a constant. While some of these characteristics or elements remain the same, some of these values can vary (e.g., the price of a dozen donuts can change from $2.50 to $3.00), we call these characteristics or elements variables. Variable is the generic term for any characteristic or element that changes. You should be able to determine which characteristics or elements are constants and which are variables.

Example Which of the following are variables and which are constants? The temperature outside your house. The number of square feet in a room that is 12 ft by 12 ft The noise level at a concert or class. Price of a gallon of gas. Number of inches in a foot. Number of leaves on a tree. Capacity of the gas tank of your car.

Data Types A data type is a set of values together with operations (functions) on that set. E.g. the set of real numbers together with the operations +,,, /. Often one has a system of data types, i.e. multiple named sets and operations that can have input and output values from different sets. E.g. < is an operation that takes two numbers and returns a Boolean value (true or false).

Implementation Implementations of data types on computers are often limited. If the result of an operation falls outside the implemented subset, the result is undefined. E.g.: The program is aborted with an error message. The program continues to work, but with a wrong value. E.g. adding two large positive numbers gives a negative number.

Data Types Primary Data Types Void Character Integer Floating Boolean Composite Data Types Array String Pointer Structure Union Enum etc.

Operators An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and variables Ex: a+b 1. Arithmetic operators 2. Relational operators 3. Logical operators 4. Assignment operators 5. Increment and decrement operators 6. Conditional operators 7. Bitwise operators 8. Special operators

Arithmetic Operators

Relational Operators

Logical Operators Logical expression or a compound relational expression An expression that combines two or more relational expressions Ex: if (a==b && b==c)

Truth Table

Assignment Operators Syntax: v op = exp; Where v = variable, op = shorthand assignment operator exp = expression Ex: x=x+3 x+=3

Shorthand Assignment Operators

Increment & Decrement Operators 2 useful operators namely Increment ++ Decrement operators The ++ operator adds a value 1 to the operand The -- operator subtracts 1 from the operand ++a or a++ --a or a--

Rules for ++ & -- Operators 1. These require variables as their operands 2. When postfix either ++ or is used with the variable in a given expression, the expression is evaluated first and then it is incremented or decremented by one 3. When prefix either ++ or is used with the variable in a given expression, it is incremented or decremented by one first and then the expression is evaluated with the new value

Examples for ++ & -- operators Let the value of a =5 and b=++a then a = b =6 Let the value of a = 5 and b=a++ then a =6 but b=5 i.e.: 1. a prefix operator first adds 1 to the operand and then the result is assigned to the variable on the left 2. a postfix operator first assigns the value to the variable on left and then increments the operand.

Conditional Operators Syntax: exp1? exp2 : exp3 Where exp1,exp2 and exp3 are expressions Working of the? Operator: Exp1 is evaluated first, if it is nonzero(1/true) then the expression2 is evaluated and this becomes the value of the expression, If exp1 is false(0/zero) exp3 is evaluated and its value becomes the value of the expression Ex: m=2; n=3 r=(m>n)? m : n;

Bitwise Operators These operators allow manipulation of data at the bit level

Arithmetic Expressions ab c a b S= a b 2 c

Rules for evaluation of expression 1. First parenthesized sub expression from left to right are evaluated. 2. If parentheses are nested, the evaluation begins with the innermost sub expression 3. The precedence rule is applied in determining the order of application of operators in evaluating sub expressions 4. The associatively rule is applied when 2 or more operators of the same precedence level appear in a sub expression. 5. Arithmetic expressions are evaluated from left to right using the rules of precedence 6. When parentheses are used, the expressions within parentheses assume highest priority

Example Evaluate the expression when a=4 b=a- ++a =a 5 =5-5 =0