VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Structure of a C program
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
JavaScript, Third Edition
Introduction to C Programming
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.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
2440: 211 Interactive Web Programming Expressions & Operators.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
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.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
CSCI 171 Presentation 2. Program Components main() #include Variable Definition Function Prototype Program Statements Function Call Function Definition.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
At the end of the module the students should be able to:  Familiarize themselves with the different uses of constants, operators, and expressions in.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
Primitive Variables.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
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.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Arithmetic Operations (L05) * Arithmetic Operations * Variables * Declaration Statement * Software Development Procedure Problem Solving Using C Dr. Ming.
Prepared By: K. U. Khimani Assistant Professor IT Department.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
BASIC ELEMENTS OF A COMPUTER PROGRAM
INSPIRING CREATIVE AND INNOVATIVE MINDS
Tokens in C Keywords Identifiers Constants
Data Types, Identifiers, and Expressions
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Revision Lecture
Java Programming: From Problem Analysis to Program Design, 4e
By: Syed Shahrukh Haider
Introduction to C Programming
Arrays, For loop While loop Do while loop
Data Types, Identifiers, and Expressions
Chapter 2 - Introduction to C Programming
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Introduction to C++ Programming
Basics of ‘C’.
Chapter 2 - Introduction to C Programming
Introduction to C Programming
C++ Data Types Data Type
Lectures on Numerical Methods
Expressions and Assignment
C Programming Getting started Variables Basic C operators Conditionals
The Data Element.
Chapter 4: Expression and Operator
Primitive Types and Expressions
The Data Element.
Lexical Elements & Operators
Introduction to C Programming
Presentation transcript:

VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION

Identifiers Defined Identifiers are composed of a sequence of letters. Digits, and the special character _ (underscore). Avoid using names that are too short or too long. Limit the identifiers from 8 to 15 characters only.

Variables Defined Variables are identifiers that can store a changeable value. These can be different data types.

Rules for defining or naming identifiers It must consist only of letters, digits, and underscore. Example: _duh, num_1 (correct)

Rules for defining or naming identifiers It should not begin with a digit. Example: 1name, 3to3 (incorrect)

Rules for defining or naming identifiers An identifier defined in the C standard library should not be redefined. Example: printf, scanf (incorrect)

Rules for defining or naming identifiers It is case sensitive; meaning uppercase is not equal to the lowercase. Example: ans != Ans != aNs

Rules for defining or naming identifiers Do not include embedded blanks. Example: large num (incorrect)

Rules for defining or naming identifiers Do not use any of the C language keywords as your variable/ identifier. Do not call your variable / identifier by the same name as other functions.

Variable Declaration All variables must be declared before they may be used. The general form of declaration is shown here: Type variable list; Example: int i,j, k; short i,j,k;

Variable Declaration Note: Before declaring variables, specify first the data type of the variable/s. Variables must be separated by comma. All declarations must be terminated by a semicolon (;).

Two kinds of variables Local Variables Global Variables

Local Variables Variables that are declared inside a function are called local variables. It can only be referenced by statements that are inside the block in which the variables are declared.

Local Variables Example: #include<stdio.h> main() { int a,b,c; ______; }

Global Variables Global variables are known throughout the entire program and may be used by any piece of code. Global variables are created by declaring them outside of any function.

Global Variables Example: #include<stdio.h> int a,b,c; main() { ________; }

Constants Defined Constants are identifier / variables that can store a value that cannot be changed during program execution. Example: const int count = 100; Where integer count has a fixed value of 100.

Arithmetic, Logical, Relational, and Bitwise Operations Operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. There are three classes of operators in C: arithmetic, logical and relational, and bitwise.

Arithmetic Operators Operator Action + Addition - Subtraction * Multiplication / Division % Modulus Divisor -- Decrement a value ++ Increment a value

Relational and Logical Operators In the term relational operator, the word relational refers to the relationship values can have with one another. In the term logical operator, the word logical refers to the ways these relationships can be connected together using the rules of formal logic.

Relational Operators Operators Action > Greater than >= Greater than or equal to < Less than <= Less than or equal to == equal != Not equal

Logical Operators Operators Action Truth Table && AND true && true = true true && false = false false && true = false false && false = false || OR true && true = true true && false = true false && true = true ! NOT !true = false !false = true

Bitwise Operator Bitwise operators are the testing, setting or shifting of the actual bits in a byte or a word, which corresponds to C’s standard char and int data types and variants. Bitwise operators cannot by used on type float, double, long double, void or other more complex types.

The ? Operator ? Operator is a very powerful and convenient operator that can be used to replace certain statements of the if-then-else form. Example: y= x > 9 ? 100: 200 is equivalent to If (x>9) y=100; Else Y=200;

Evaluation of Expression Expression refers to anything that evaluates to a numeric value.

Order of Precedence Order of Precedence () !, unary +, - *. /. % binary + , - <, <=, >, >= ==, != && ||

Evaluate the following Given: z= 5; a = 3; b=9; w= 2; y=5 Expression Z – (a * b / 2) + w + y

Converting Mathematical Formula to C expression Example: b2 – 4ac = b * b – 4 * a * c

Converting English Conditions to C expression Example: X and y greater than z can be converted to Z = x > && y > z