BSM540 Basics of C Language

Similar documents
BSM540 Basics of C Language

Unit 4. Input/Output Functions

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Chapter 3 Basic Data Types. Lecture 3 1

sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ;

THE FUNDAMENTAL DATA TYPES

UNIT 7A Data Representation: Numbers and Text. Digital Data

BSM540 Basics of C Language

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

Chapter 3. Fundamental Data Types

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

Number Systems, Scalar Types, and Input and Output

Sir Syed University of Engineering and Technology. Computer Programming & Problem Solving ( CPPS )

Chapter 2 THE STRUCTURE OF C LANGUAGE

Engineering Computing I

Fundamentals of Programming. Lecture 11: C Characters and Strings

Programming in C++ 4. The lexical basis of C++

Work relative to other classes

Fundamentals of C Programming

CSC 1107: Structured Programming

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

Basic Elements of C. Staff Incharge: S.Sasirekha

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

COMP2121: Microprocessors and Interfacing. Number Systems

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

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

Data Types and Variables in C language

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

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

Basic Types and Formatted I/O

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Lecture 02 C FUNDAMENTALS

공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -VARIABLE AND DATA TYPES- SPRING 2015, SEON-JU AHN, CNU EE

Input/Output Week 5:Lesson 16.1

Reserved Words and Identifiers

CHAPTER-6 GETTING STARTED WITH C++

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Chapter 7. Basic Types

Lecture 3. More About C

MACHINE LEVEL REPRESENTATION OF DATA

ANSI C Programming Simple Programs

Declaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used.

Introduction to Computers and Programming. Numeric Values

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

Week 3 Lecture 2. Types Constants and Variables

Java Basic Datatypees

C Programming Language

Lecture 2 Tao Wang 1

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

Should you know scanf and printf?

AWK - PRETTY PRINTING

Computer System and programming in C

CS 31: Intro to Systems Binary Representation. Kevin Webb Swarthmore College January 27, 2015

Introduction to Computing Lecture 03: Basic input / output operations

Computers Programming Course 5. Iulian Năstac

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

Fundamentals of Programming

Fundamentals of Programming Session 4

Fundamental of Programming (C)

First of all, it is a variable, just like other variables you studied

Time (self-scheduled): Location Schedule Your Exam: What to bring:

C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

COP 3275: Chapter 07. Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA

C: How to Program. Week /Mar/05

Formatted Input/Output

Formatting functions in C Language

VARIABLES AND CONSTANTS

Getting started with Java

1/25/2018. ECE 220: Computer Systems & Programming. Write Output Using printf. Use Backslash to Include Special ASCII Characters

Variables and Literals

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

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

Chapter 2 - Introduction to C Programming

Beginning C Programming for Engineers

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

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Types, Operators and Expressions

Data Type Fall 2014 Jinkyu Jeong

ARG! Language Reference Manual

Data Types. Data Types. Integer Types. Signed Integers

C Programming Language

IT 1033: Fundamentals of Programming Data types & variables

COMP2611: Computer Organization. Data Representation

Data Representation in Computer Memory

Lecture 1: Introduction to Microprocessors

CC112 Structured Programming

Fundamentals of C. Structure of a C Program

File Handling in C. EECS 2031 Fall October 27, 2014

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

printf( Please enter another number: ); scanf( %d, &num2);

Transcription:

BSM540 Basics of C Language Chapter 3: Data and C Prof. Manar Mohaisen Department of EEC Engineering

Review of the Precedent Lecture Explained the structure of a simple C program Introduced comments in C language Explained variable declaration and assignment Introduced printf() function Introduced a multi-function program Gave several C keywords 2

Lecture Objectives To explain the input/output functions printf() and scanf() To explain how to define and treat variables of several data types Integers, floating-point, and characters To introduce nonprinting sequences To give several programming examples To give several C keywords 3

A Simple Program What is new? float data type: float can hold number with decimal points such as 3.42 %f specifier: This specifier is used to handle a floating-point variable scanf() functions: This functions reads values or strings from the keyboard 4

Input/output functions A Simple Program contd. 5

Data-type Data-type Keywords The size of each data type might vary from a computer/os to another On Windows XP 32bits, MS Visual Studio 6, you get the following values 6

Integer Handling Integers An integer does not have a fractional part Identifiers: int, short int, signed int, unsigned int, short, signed, unsigned %d notation is used to indicate an integer value 7

Handling Integers contd. Other types of integers Wrong specifications might produce unexpected results. 8

Note Octal & Hexadecimal Decimal numbers (i.e., integers) are base 10, octal are base 8, and hexadecimal are base 16 Example: 100 decimal: 1x10 2 + 0x10 1 + 0x10 0 = 100 100 decimal = 1x8 2 + 4x8 1 + 4x8 0 = 144 octal 100 decimal = 6x16 1 + 4 x16 0 = 64 hexadecimal 9

Character Character representation Each character is represented in computer using the ASCII code For example: the ASCII 65 is equivalent to the letter A The ASCII runs from 0 to 127 There 1 Byte is more than enough to encompass the standard ASCII code 10

Example Try with other characters Character contd. 11

Nonprinting Characters 12

Representation Types float and double 1.4E15: 1.4 is the significand and 15 is the exponent float data-type 24 bits are used for the significand and its sign 8 bits are used for the exponent and its sign double data-type (in general) 56 bits are used for the significand and its sign 8 bits are used for the exponent and its sign 13

Better printout Types float and double contd. 14

Variables and memory usage Size of Data Types 15

What is new? Example: Escape Sequences \a (alert), \r (carriage return), \b (backspace) %.2f : Prints the non-fractional part and only the first two digits of the fractional part 16

Keywords Lecture Keywords Input/output functions (printf() and scanf()) Data types: integer- and float-precision Decimal, octal, hexadecimal systems Nonprinting sequences sizeof(): size of data types Escape sequences 17

Lecture Summary To explain the input/output functions printf() and scanf() To explain how to define and treat variables of several data types Integers, floating-point, and characters To introduce nonprinting sequences To give several programming examples To give several C keywords 18