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

Size: px
Start display at page:

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

Transcription

1 1

2 Literal Constants Definition A literal or a literal constant is a value, such as a number, character or string, which may be assigned to a variable or a constant. It may also be used directly as a function parameter or an operand in an expression. Literals Are "hard coded" values May be numbers, characters or strings May be represented in a number of formats (decimal, hexadecimal, binary, character, etc.) Always represent the same value (5 always represents the quantity five) 2

3 Constant vs. Literal What's the difference? Terms are used interchangeably in most programming literature A literal is a constant, but a constant is not a literal #define MAXINT const int MAXINT = 32767; For purposes of this presentation: Constantsare labels that represent a literal Literalsare values, often assigned to symbolic constants and variables Literal Constants Four basic types of literals: Integer Floating Point Character String Integer and Floating Point are numeric type constants: Commas and spaces are not allowed Value cannot exceed type bounds May be preceded by a minus sign 3

4 Integer Literals Decimal (Base 10) Cannot start with 0 (except for 0 itself) Cannot include a decimal point Valid Decimal Integers: Invalid Decimal Integers: 32, Integer Literals Hexadecimal (Base 16) Must begin with 0x or 0X (that s zero x) May include digits 0 9 and A F / a f Valid Hexadecimal Integers: 0x 0x1 0x0A2B 0xBEEF Invalid Hexadecimal Integers: 0x5.3 0EA12 0xEG 53h 4

5 Integer Literals Octal (Base 8) Must begin with 0 (zero) May include digits 0 7 Valid Octal Integers: Invalid Octal Integers: o o While Octal is still part of the ANSI specification, almost no one uses it anymore. Integer Literals Binary (Base 2) Must begin with 0b or 0B (that s zero b) May include digits 0 and 1 Valid Binary Integers: 0b 0b1 0b Invalid Binary Integers: 0b b12 10b ANSI C does not specify a format for binary integer literals. However, this notation is supported by most compilers. 5

6 Integer Literals Qualifiers Like variables, literals may be qualified A suffix is used to specify the modifier U or u for unsigned: 25u L or l for long: 25L 'F' or 'f' for float: 10f or 10.25F Suffixes may be combined: 0xF5UL Note: U must precede L Numbers without a suffix are assumed to be signed and short Floating Point Literals Decimal (Base 10) Like decimal integer literals, but decimal point is allowed e notation is used to specify exponents (ke±n k 10 ±n ) Valid Floating Point Literals: 2.56e e f Invalid Floating Point Literals: 0x5Ae F2.33 6

7 Character Literals Specified within single quotes (') May include any single printable character May include any single non printable character using escape sequences (e.g. '\0' = NUL) (also called digraphs) Valid Characters: 'a', 'T', '\n', '5', ' ' (space) Invalid Characters: 'me', '23', ''' String Literals Specified within double quotes (") May include any printable or non printable characters (using escape sequences) Usually terminated by a null character \0 Valid Strings: "Microchip", "Hi\n", "PIC", "He said, \"Hi\"" Invalid Strings: "He said, "Hi"" 7

8 String Literals Declarations Strings are a special case of arrays If declared without a dimension, the null character is automatically appended to the end of the string: Example 1 Wrong Way char color[3] = "RED"; Is stored as: color[0] = 'R' color[1] = 'E' color[2] = 'D' NOT a complete string no '\0' at end Example 2 Right Way char color[] = "RED"; Is stored as: color[0] = 'R' color[1] = 'E' color[2] = 'D' color[3] = '\0' String Literals How to Include Special Characters in Strings Escape Sequence Character ASCII Value \a \b \t \n \v \f \r \" \' \? \\ \0 BELL (alert) Backspace Horizontal Tab Newline (Line Feed) Vertical Tab Form Feed Carriage Return Quotation Mark (") Apostrophe/Single Quote (') Question Mark (?) Backslash (\) Null

9 Example String Literals How to Include Special Characters in Strings char message[] = "Please enter a command \n" This string includes a newline character Escape sequences may be included in a string like any ordinary character The backslash plus the character that follows it are considered a single character and have a single ASCII value Definition A constant or a symbolic constant is a label that represents a literal. Anywhere the label is encountered in code, it will be interpreted as the value of the literal it represents. Constants Once assigned, never change their value Make development changes easy Eliminate the use of "magic numbers" Two types of constants Text Substitution Labels Variable Constants (!!??) 9

10 Some texts on C declare constants like: Example This is not efficient for an embedded system: A variable is allocated in program memory, but it cannot be changed due to the const keyword This is not the traditional use of const In the vast majority of cases, it is better to use #define for constants Constant Variables Using const const float PI = ; Text Substitution Labels Using #define Defines a text substitution label Syntax #define label text Each instance of label will be replaced with text by the preprocessor unless label is inside a string No memory is used in the microcontroller Example #define PI #define mol 6.02E23 #define MCU "PIC24FJ128GA010" #define COEF 2 * PI 10

11 #define Gotchas Note: a #define directive is NEVER terminated with a semi colon (;), unless you want that to be part of the text substitution. Example #define MyConst 5; c = MyConst + 3; c = 5; + 3; Example Initializing Variables When Declared A constant declared with const may not be used to initialize a global or static variable when it is declared (though it may be used to initialize local variables ) #define CONSTANT1 5 const CONSTANT2 = 10; int variable1 = CONSTANT1; int variable2; // Cannot do: int variable2 = CONSTANT2 11

12 Lab Exercise 2 Open the lab Project: On the class website Examples -> Lab2.zip Exercise 02 1 Open MPLAB X and select Open Project Icon (Ctrl + Shift + O) Open the project listed above. If you already have a project open in MPLAB X, close it by right clicking on the open project and selecting Close 12

13 Compile and run the code: Exercise 02 2 Debug Project 4 Pause 3 Continue 2 Click on the Debug Project button. 3 If no errors are reported, click on Continue button to start the program. 4 Click on the Pause button. Expected Results (1): Exercise 02 5 The UART 1 Output window should show the text that is output by the program, indicating the values of the two symbolic constants in the code. 13

14 Expected Results (2): Exercise 02 Only CONSTANT2 can be added to Watches Window CONSTANT1 has no address 6 CONSTANT1 cannot be added CONSTANT2 has address of 0x8CC Expected Results (3): Exercise 02 Program Memory only contains CONSTANT2 CONSTANT1 not in Program Memory 7 CONSTANT2 has the address x0bcc CONSTANT2 has a value of 0x00CC 14

15 Exercise 02 Conclusions Constants make code more readable Constants improve maintainability #define should be used to define constants #define constants use no memory, so they may be used freely const should never be used in this context (it has other uses ) printf() Standard Library Function Used to write text to the "standard output" Normally a computer monitor or printer Often the UART in embedded systems SIM Uart1 window in MPLAB SIM 15

16 printf() Standard Library Function Syntax printf(controlstring, arg1, argn); Everything printed verbatim within string except %d's which are replaced by the argument values from the list Example int a = 5, b = 10; printf("a = %d\nb = %d\n", a, b); Result: a = 5 b = 10 NOTE: the 'd' in %d is the conversion character. (See next slide for details) printf() Conversion Characters for Control String Conversion Character %c %s %d %o %u %x %X %f %e %E %g %G Meaning Single character String (all characters until '\0') Signed decimal integer Unsigned octal integer Unsigned decimal integer Unsigned hexadecimal integer with lowercase digits (1a5e) As x, but with uppercase digits (e.g. 1A5E) Signed decimal value (floating point) Signed decimal with exponent (e.g. 1.26e 5) As e, but uses E for exponent (e.g. 1.26E 5) As e or f, but depends on size and precision of value As g, but uses E for exponent 16

17 printf() Gotchas The value displayed is interpreted entirely by the formatting string: printf("ascii = %d", 'a'); will output: ASCII = 97 A more problematic string: printf("value = %d", 6.02e23); will output: Value = Incorrect results may be displayed if the format type doesn't match the actual data type of the argument printf() Useful Format String Examples for Debugging Print a 16 bit hexadecimal value with a "0x" prefix and leading zeros if necessary to fill a 4 hex digit value: printf("address of x = %#06x\n", x_ptr); # Specifies that a 0x or 0X should precede a hexadecimal value (has other meanings for different conversion characters) 06 Specifies that 6 characters must be output (including 0x prefix), zeros will be filled in at left if necessary x Specifies that the output value should be expressed as a hexadecimal integer 17

18 printf() Useful Format String Examples for Debugging Same as previous, but force hex letters to uppercase while leaving the 'x' in '0x' lowercase: printf("address of x = 0x%04X\n", x_ptr); 04 Specifies that 4 characters must be output (no longer including 0x prefix since that is explicitly included in the string), zeros will be filled in at left if necessary X Specifies that the output value should be expressed as a hexadecimal integer with uppercase A F 18

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

DECLARATIONS Character Set, Keywords, Identifiers, Constants, Variables Character Set C uses the uppercase letters A to Z. C uses the lowercase letters a to z. C uses digits 0 to 9. C uses certain Special

### Basic Elements of C. Staff Incharge: S.Sasirekha

Basic Elements of C Staff Incharge: S.Sasirekha Basic Elements of C Character Set Identifiers & Keywords Constants Variables Data Types Declaration Expressions & Statements C Character Set Letters Uppercase

### Work relative to other classes

Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language

### VARIABLES AND CONSTANTS

UNIT 3 Structure VARIABLES AND CONSTANTS Variables and Constants 3.0 Introduction 3.1 Objectives 3.2 Character Set 3.3 Identifiers and Keywords 3.3.1 Rules for Forming Identifiers 3.3.2 Keywords 3.4 Data

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

1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

### Variables and Literals

C++ By 4 EXAMPLE Variables and Literals Garbage in, garbage out! To understand data processing with C++, you must understand how C++ creates, stores, and manipulates data. This chapter teaches you how

### Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

Overview of C Basic Data Types Constants Variables Identifiers Keywords Basic I/O NOTE: There are six classes of tokens: identifiers, keywords, constants, string literals, operators, and other separators.

### Basic Types and Formatted I/O

Basic Types and Formatted I/O C Variables Names (1) Variable Names Names may contain letters, digits and underscores The first character must be a letter or an underscore. the underscore can be used but

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

ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 07: Data Input and Output Readings: Chapter 4 Input /Output Operations A program needs

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

C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

### CSC 1107: Structured Programming

CSC 1107: Structured Programming J. Kizito Makerere University e-mail: www: materials: e-learning environment: office: alt. office: jkizito@cis.mak.ac.ug http://serval.ug/~jona http://serval.ug/~jona/materials/csc1107

### Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

### Programming for Engineers Introduction to C

Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

### Unit 4. Input/Output Functions

Unit 4 Input/Output Functions Introduction to Input/Output Input refers to accepting data while output refers to presenting data. Normally the data is accepted from keyboard and is outputted onto the screen.

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

Standard 11 Lesson 9 Introduction to C++( Up to Operators) 2MARKS 1. Why C++ is called hybrid language? C++ supports both procedural and Object Oriented Programming paradigms. Thus, C++ is called as a

### BSM540 Basics of C Language

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

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

UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

### Fundamental of C programming. - Ompal Singh

Fundamental of C programming - Ompal Singh HISTORY OF C LANGUAGE IN 1960 ALGOL BY INTERNATIONAL COMMITTEE. IT WAS TOO GENERAL AND ABSTRUCT. IN 1963 CPL(COMBINED PROGRAMMING LANGUAGE) WAS DEVELOPED AT CAMBRIDGE

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

Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++

### 6.096 Introduction to C++ January (IAP) 2009

MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

### Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

### Fundamentals of Programming. Lecture 3: Introduction to C Programming

Fundamentals of Programming Lecture 3: Introduction to C Programming Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department Outline A Simple C

### Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

### Chapter 2 THE STRUCTURE OF C LANGUAGE

Lecture # 5 Chapter 2 THE STRUCTURE OF C LANGUAGE 1 Compiled by SIA CHEE KIONG DEPARTMENT OF MATERIAL AND DESIGN ENGINEERING FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING Contents Introduction to

### Data Types and Variables in C language

Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are

### AWK - PRETTY PRINTING

AWK - PRETTY PRINTING http://www.tutorialspoint.com/awk/awk_pretty_printing.htm Copyright tutorialspoint.com So far we have used AWK's print and printf functions to display data on standard output. But

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

Programming in C and Data Structures [15PCD13/23] 1 PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme] Course objectives: The objectives of this course is to make students

### INTRODUCTION 1 AND REVIEW

INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

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

Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

### c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

### Fundamental of Programming (C)

Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

### Fundamentals of Programming. Lecture 11: C Characters and Strings

1 Fundamentals of Programming Lecture 11: C Characters and Strings Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department The lectures of this

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

C Fundamentals & Formatted Input/Output adopted from KNK C Programming : A Modern Approach C Fundamentals 2 Program: Printing a Pun The file name doesn t matter, but the.c extension is often required.

### 2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

### Differentiate Between Keywords and Identifiers

History of C? Why we use C programming language Martin Richards developed a high-level computer language called BCPL in the year 1967. The intention was to develop a language for writing an operating system(os)

### HP C/iX Reference Manual

HP C/iX Reference Manual HP 3000 MPE/iX Computer Systems Edition 3 Manufacturing Part Number: 31506-90011 E0499 U.S.A. April 1999 Notice The information contained in this document is subject to change

### CS102: Variables and Expressions

CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of

### Types, Operators and Expressions

Types, Operators and Expressions EECS 2031 18 September 2017 1 Variable Names (2.1) l Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a keyword.

### Number Systems, Scalar Types, and Input and Output

Number Systems, Scalar Types, and Input and Output Outline: Binary, Octal, Hexadecimal, and Decimal Numbers Character Set Comments Declaration Data Types and Constants Integral Data Types Floating-Point

### Programming and Data Structures

Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()

### 1.1 Introduction to C Language. Department of CSE

1.1 Introduction to C Language 1 Department of CSE Objectives To understand the structure of a C-Language Program To write a minimal C program To introduce the include preprocessor command To be able to

### Full file at C How to Program, 6/e Multiple Choice Test Bank

2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

### Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

CSC 2400: Computer Systems Data Representa5on What kinds of data do we need to represent? - Numbers signed, unsigned, integers, floating point, complex, rational, irrational, - Text characters, strings,

### Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

CSC 2400: Computer Systems Data Representa5on What kinds of data do we need to represent? - Numbers signed, unsigned, integers, floating point, complex, rational, irrational, - Text characters, strings,

### Variables, Constants, and Data Types

Variables, Constants, and Data Types Strings and Escape Characters Primitive Data Types Variables, Initialization, and Assignment Constants Reading for this lecture: Dawson, Chapter 2 http://introcs.cs.princeton.edu/python/12types

### ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

ME240 Computation for Mechanical Engineering Lecture 4 C++ Data Types Introduction In this lecture we will learn some fundamental elements of C++: Introduction Data Types Identifiers Variables Constants

### C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

### XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.

XC Specification IN THIS DOCUMENT Lexical Conventions Syntax Notation Meaning of Identifiers Objects and Lvalues Conversions Expressions Declarations Statements External Declarations Scope and Linkage

### Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define

### Data Types Literals, Variables & Constants

C/C++ PROGRAMMING Data Types Literals, Variables & Constants Copyright 2013 Dan McElroy Under the Hood As a DRIVER of an automobile, you may not need to know everything that happens under the hood, although

### A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

1 29 Formatted Output 2 OBJECTIVES In this chapter you will learn: To understand input and output streams. To use printf formatting. To print with field widths and precisions. To use formatting flags in

### 2 nd Week Lecture Notes

2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

### Lecture 2: C Programming Basic

ECE342 Introduction to Embedded Systems Lecture 2: C Programming Basic Ying Tang Electrical and Computer Engineering Rowan University 1 Facts about C C was developed in 1972 in order to write the UNIX

### Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Chapter 18 I/O in C Standard C Library I/O commands are not included as part of the C language. Instead, they are part of the Standard C Library. A collection of functions and macros that must be implemented

### Lexical Considerations

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

### Chapter 2, Part I Introduction to C Programming

Chapter 2, Part I Introduction to C Programming C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 2016 Pearson Education, Ltd. All rights reserved. 2 2016 Pearson Education,

### Chapter 2. Lexical Elements & Operators

Chapter 2. Lexical Elements & Operators Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr The C System

### CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

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

C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing

### JAVA Programming Fundamentals

Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

### THE FUNDAMENTAL DATA TYPES

THE FUNDAMENTAL DATA TYPES Declarations, Expressions, and Assignments Variables and constants are the objects that a prog. manipulates. All variables must be declared before they can be used. #include

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

University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Review: Basic I/O in C Allowing Input from the Keyboard, Output to the Monitor

### Input/Output Week 5:Lesson 16.1

Input/Output Week 5:Lesson 16.1 Commands (On-Line) scanf/printf Principles of Programming-I / 131101 Prepared by: Dr. Bahjat Qazzaz --------------------------------------------------------------------------------------------

>B

### LEXICAL 2 CONVENTIONS

LEXIAL 2 ONVENTIONS hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. ++ Programming Lexical onventions Objectives You will learn: Operators. Punctuators. omments. Identifiers. Literals. SYS-ED \OMPUTER EDUATION

Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

### ANSI C Programming Simple Programs

ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

### Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

Exercises Software Development I 03 Data Representation Data types, range of values, ernal format, literals October 22nd, 2014 Software Development I Wer term 2013/2014 Priv.-Doz. Dipl.-Ing. Dr. Andreas

### CS1100 Introduction to Programming

CS1100 Introduction to Programming Arrays Madhu Mutyam Department of Computer Science and Engineering Indian Institute of Technology Madras Course Material SD, SB, PSK, NSN, DK, TAG CS&E, IIT M 1 An Array

### C Programming

204216 -- C Programming Chapter 3 Processing and Interactive Input Adapted/Assembled for 204216 by Areerat Trongratsameethong A First Book of ANSI C, Fourth Edition Objectives Assignment Mathematical Library

### C: How to Program. Week /Mar/05

1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

### Java Basic Datatypees

Basic Datatypees Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. Based on the data type of a variable,

### INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 printf and scanf Streams (input and output)

### ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.

### Basics of Java Programming

Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

### CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

### Full file at

Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

### Fundamentals of Programming

Fundamentals of Programming Lecture 4 Input & Output Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline printf scanf putchar getchar getch getche Input and Output in

### IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

Subject code - CCP01 Chapt Chapter 1 INTRODUCTION TO C 1. A group of software developed for certain purpose are referred as ---- a. Program b. Variable c. Software d. Data 2. Software is classified into

### PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name

### Fundamental of Programming (C)

Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi CE 43 - Fall 97 Lecture 4 Input and Output Department of Computer Engineering Outline printf

### Types, Operators and Expressions

Types, Operators and Expressions CSE 2031 Fall 2011 9/11/2011 5:24 PM 1 Variable Names (2.1) Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a

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

TOKENS C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, \$ # ; :? & White Spaces:- Blank Space, Horizontal Tab, Vertical tab, Carriage Return. Other Characters:-

### Basics of Programming

Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the

### Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

1 Professor: Sana Odeh odeh@courant.nyu.edu Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators Review What s wrong with this line of code? print( He said Hello ) What s wrong with

### Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

### LECTURE 02 INTRODUCTION TO C++

PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION

### Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical

### C Language, Token, Keywords, Constant, variable

C Language, Token, Keywords, Constant, variable A language written by Brian Kernighan and Dennis Ritchie. This was to be the language that UNIX was written in to become the first "portable" language. C

### Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other

### Lexical Considerations

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

### 3 The Building Blocks: Data Types, Literals, and Variables

chapter 3 The Building Blocks: Data Types, Literals, and Variables 3.1 Data Types A program can do many things, including calculations, sorting names, preparing phone lists, displaying images, validating

### Getting started with Java

Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving

### Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Objectives. In this chapter, you will:

Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

### Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers