Assignment Operators =, +=, *= A += B means (A+B) --->A or A = (A+B) Similarly true for -=, *=, /=, and %=. The basic rule is from right to left. Never.

Slides:



Advertisements
Similar presentations
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Advertisements

Sizes of simple data types sizeof(char) = 1 size(short) = 2 sizeof(int) = 4 size(long) = 8 sizeof(char) = 1 size(short) = 2 sizeof(int) = 2 size(long)
Primitive Variable types Basic types –char (single character or ASCII integer value) –int (integer) –short (not longer than int) –long (longer than int)
Structure of a C program
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
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.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Chapter 2 Data Types, Declarations, and Displays
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations System-oriented Programming, B. Hirsbrunner,
Binary Number Systems.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Week 3 - Monday.  What did we talk about last time?  Math library  Preprocessor directives  Lab 2.
Chapter 4 Numbers. Python Program Structure Python programs consist of: Modules Statements Expressions Objects.
C/C++ Operators Binary Operators: Operators Between Two Operands: Operator + MeaningExample Definition. Additionx = 6 + 2;Add the values on either side.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
C++ Programming: Basic Elements of C++.
Characters and tokens Characters are the basic building blocks in C program, equivalent to ‘letters’ in English language Includes every printable character.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
ISBN Chapter 7 Expressions and Assignment Statements.
 All C programs are made up of functions that perform operations on variables.  In this lecture we examine variables  Variables are the basic building.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
4. EXPRESSIONS. Display the value of pi, to 5 decimal places, right justified, in 9 columns Read in someone’s height in feet and inches using.
Chapter2 Constants, Variables, and Data Types. 2.1 Introduction In this chapter, we will discuss –constants (integer, real, character, string, enum),symbolic.
Module B - Computation1/61 Module-B-Computation Variables Basic Memory Operations Expressions.
Enumerated Types Sometimes we may wish to have a variable whose values are not numeric, for example, the variable size might have values coming from the.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
INTRODUCTION TO ‘C’ PROGRAMMING BY Prof. P. PADMANABHAM M.Tech (AE), M.Tech(CS), Ph.D(CS)-FIETE, FIE Director Academics, Bharat Institute Of Engineering.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
Gator Engineering Project 1 Grades released Re-grading –Within one week –TA: Fardad, or office hours: MW 2:00 – 4:00 PM TA Huiyuan’s office hour.
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
CSE 220 – C Programming Bitwise Operators.
Data types Data types Basic types
Chap. 2. Types, Operators, and Expressions
Week 3 - Friday CS222.
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
ECE Application Programming
EPSII 59:006 Spring 2004.
C Basics.
What to bring: iCard, pens/pencils (They provide the scratch paper)
Fundamental Data Types
Introduction to C Programming
Variables, Types and Expressions
Variables, Types and Expressions
Introduction to Programming
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Basics of ‘C’.
Introduction to C Programming
Chapter 3 Operators and Expressions
Comp Org & Assembly Lang
Fundamental Data Types
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
Lexical Elements & Operators
DATA TYPES There are four basic data types associated with variables:
Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a language-specific syntactical token.
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

Assignment Operators =, +=, *= A += B means (A+B) --->A or A = (A+B) Similarly true for -=, *=, /=, and %=. The basic rule is from right to left. Never use an expression such as: 5 += A, It will make no sense.

Unary and Binary Operators Prefix and unary Right to Left (Associativity rule) int X=5, Y; Y = -X++; After running the program statements, Y = ? X = ? Week04 pre.c

Type Conversion in C When an operator is applied to two variables of the different type will result in an error in most program languages. C has a clear set of rules that govern most cases. ** In general, when we have two different types, the “most restrictive” type is converted into the “least restrictive” type.**

Types for different numbers in C 1. int x - 32 bits - or 16 bits x = ?(range) ** Multiply or divide two integer in range can cause out of range error in C so that it will cause fatal errors in some situations** (in most other programs, it will give you a run time error and terminate the program)

Long and Short Integers Typically, short int is 16 bits -- %hd long int is 32 bits -- %/ld Nowadays, it is not a good idea to use short int in any situation. The main advantage of using type int is to speed up processing time.

Real World --- Real Number Floating-Point Type and Constant In the real world, real numbers dominate. double -- normally eight bytes memory is reserved for a double. --- %f %lf -- ** A decimal point or exponential part must be supplied when representing floating point constant. ** float, double, and long double double is the default type in most of the C

“String Constant in C” One token rule: “this” “is” “a” “test” will be interpreted as “thisisatest” /* */ inside a string no longer mean a comment. Week04 one_token.c

Octal and Hexadecimal Numbers We use 0 in front a number to represent an octal number, such as 0377 is 255 decimal. We use 0x to represent a hexadecimal number, such as 0xff which is 255 decimal. In printf, %o and %x are used to represent the octal and hexadecimal respectively. **Leading 0 not be used in any number if you don’t mean to use an octal number**

Bitwise operations ~ -- bitwise-negation >> -- shift right << -- shift left & -- bitwise-AND | -- bitwise-OR ^ -- bitwise -- XOR

sizeof operator It gives the number of bytes associated with a specified type or a variable. Example: size_of.c week04 sizeof2.c week04

Example Week04 bit.c

Header file limit.h Example: weeko4 limit.c

Example #include main (void) { int A, B=5, C=8; A = B++ + C++; printf (“A = %d”, A; “B= %d”, B, “C= %d\n”, C); A = B C; printf (“A = %d”, A; “B= %d”, B, “C= %d\n”, C); A = ++B + C++; printf (“A = %d”, A; “B= %d”, B, “C= %d\n”, C); A = ++B + ++C; printf (“A = %d”, A; “B= %d”, B, “C= %d\n”, C); return 0; }