Constant Variable Expression

Slides:



Advertisements
Similar presentations
Javascript Essentials How do I write it??  Start Homesite  Between the start and end BODY tags type: 
Advertisements

Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
1 Lecture 3  Lexical elements  Some operators:  /, %, =, +=, ++, --  precedence and associativity  #define  Readings: Chapter 2 Section 1 to 10.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Basic Elements of C++ Chapter 2.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
2440: 211 Interactive Web Programming Expressions & Operators.
C Tokens Identifiers Keywords Constants Operators Special symbols.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
CPS120: Introduction to Computer Science
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ Programming: Basic Elements of C++.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
Arithmetic Expressions in C++. CSCE 1062 Outline Data declaration {section 2.3} Arithmetic operators in C++ {section 2.6} Mixed data type arithmetic in.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
CPS120: Introduction to Computer Science Variables and Constants.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
What will each of the following lines print? System.out.println("number" ); number645 System.out.println("number" + (6 + 4)+ 5); number105 System.out.println(6.
Constants, Data Types and Variables
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Chapter # 2 Part 2 Programs And data
Chapter 2: Basic Elements of C++
Chapter Topics The Basics of a C++ Program Data Types
Data Types, Variables & Arithmetic
BASIC ELEMENTS OF A COMPUTER PROGRAM
Tokens in C Keywords Identifiers Constants
ITEC113 Algorithms and Programming Techniques
Basic Elements of C++.
Data Types, Identifiers, and Expressions
Revision Lecture
Java Programming: From Problem Analysis to Program Design, 4e
CSE101-Lec#3 Components of C Identifiers and Keywords Data types.
Basic Elements of C++ Chapter 2.
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Chapter 2 Edited by JJ Shepherd
With Assignment Operator
CS111 Computer Programming
Lectures on Numerical Methods
Chapter # 2 Part 2 Programs And data
Chapter 2: Introduction to C++.
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Lexical Elements & Operators
Chapter 2 Primitive Data Types and Operations
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Basic Elements of Computer Program
Programming Fundamental-1
Presentation transcript:

Constant Variable Expression CSE101-Lec#4 Constant Variable Expression

Outline In this lecture we will study Constant Variable Expression

Tokens We have seen that Tokens are broadly classified as: Identifiers Keywords Constants Variables Strings Operators Special character

Constants Lion Spanner

Constants Quick yak: Constants in daily life: Mouse buttons Sides of a hexagon Height of Mt. Everest The entity which do not change throughout the execution are called constants. Types of constants: Integer constant Character constant Floating point constants String constants Name of person remains same through out the life, example: Amit, Shubnam, etc.

Character constants String Constants Constants enclosed in single quotes(‘ ’). It can be any letter from character set. String Constants Set of zero or more characters enclosed in double quotes (eg: “ ” ) It is represented as sequence of characters within double quotes. Example : ‘\n’, ‘\t’ or ‘a’ Example : “This is C programming”

Integer Constants Floating Constant When the constant contains only digits without any decimal part Floating Constant Constants that contains number with decimal points Example : 5; -987; Example : 3.14; 309.89

My-Car In My-Car problem the constant value is 3.14 which is the value of pi and always same. pi = 3.14 Therefore: dist_travelled = 2 * pi * radius. pi is a floating point constant.

Variables Animal Tool

Variables Variable is an entity which may change. Quick yak: Variables in daily life: Whatsapp msg received in a day Voltage Length of hairs Variable is an entity which may change. Variable is used to hold result and reserve memory for the data. datatype variable_name; The naming of variable is done by following the same rules of identifier naming. Eg. What is your hobby? The answer could be reading, dancing, drawing, etc. So the answer to such questions may change during the life time of the person

Rules for naming a Variable 1. An variable name is any combination of 1 to 31 alphabets, digits or underscores. 2. The first character in the variable name must be an alphabet or underscore. 3. No blanks or special symbol other than an underscore can be used in an variable name. 4. Keywords are not allowed to be used as variables.

Variables In My-Car problem the variable was radius and dist_travelled It can also be named as radius_wheel or r1 or car_wheel_radius Distance or d1 or dist_by_1rotation

Variables Let us build some variables: For speed of car we need to know Distance traveled Time taken to travel the distance Variables to be declared as Speed, s1, speed_of_car Distance, d1, dist Time, t1, time_of_travel Variable is data name used for storing a data value  

See-Saw A bit more complex situation see-saw Variables to be declared as Weight_boy, w1, wb Distance_boy, d1, db Weight_girl, w2, wg Distance_girl, d2, dg It is to be assessed that at what distance 50Kg girl should sit in order to balance a boy of 70Kg sitting 2m away from the center ‘o’   Variable is data name used for storing a data value

Variable Initialization Assigning some value to the variable at time of creation of variable is known as variable initialization. datatype variable_name = value; During declaration no memory space is allocated to an identifier. Definition of identifier means the declaration of identifier + reservation of space for it in memory Example: int radius= 15; float pi = 3.14; char grade = ‘A’;

Expressions Expressions are the statements or the instruction given to computer to perform some operation. Every expression results in some value that can be stored in a variable. Following are few example of expressions in program: Expression to calculate speed of a car. Speed=distance/time Expression to find similarity of two things. c=value1>value2 A=b+c….three operands and 2 operators

Expressions in C are basically operators acting on operands. Quick yak: Expressions used in daily routine: Price of X kgs. Of potato Comparison of speed of two vehicles Expressions in C are basically operators acting on operands. An operand is an entity on which operation is to be performed. An operator specifies the operation to be applied on operands. Expressions are made of one or more operands. Statements like : a = b + c, ++z 300 > (8 * k) Example: addition of two numbers, 5+8, these numbers will be operands. Example: The addition, subtraction, etc will be operators

Types of Expressions The type of expression depend upon the type of operator used in the expression. It can be: Arithmetic operators. 3 + 6 = 9 4 * 2 = 8 Relational or logical operators. height_boy>=height_girl Increment and decrement operator. count=count++

Next Class: Operators Types of operators