CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018


 Edgar Ellis
 2 years ago
 Views:
Transcription
1 CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018
2 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values Data Types and Literals in C Assignment Statements and Compatibilities Type Casting Arithmetic Operators and Expressions Reading: Textbook, Chapter 2 (p , p )
3 Reserved Words A reserved word in a programming language is one with special meaning library names, variable types, flow of control statements See Appendix E in the textbook (8 th Ed.) for a list of C's reserved words They should not be used for other purposes because their meaning is wellknown to all who know the language cannot be redefined in code Examples: int, void, main, return
4 Identifiers Standard Identifiers: also have special meaning, just like reserved words e.g., names of operations or functions in libraries printf, scanf, etc. can be redefined in code  be careful! UserDefined Identifiers created and used by programmers to name memory locations (e.g., variable names, constants) Both types can be arbitrarily long, but some compilers don't consider two identifiers different unless they vary within the first 31 characters
5 C Identifier Naming Identifiers may contain only the following: Letters Digits (0 through 9) The underscore character (_) The first character cannot be a digit reserved words may not be used as identifiers Don't redefine standard identifiers this will compile and run, but is bad practice
6 C Identifiers Legal or not? i Counter tree include great1 cow_barn cowbarn 7thvariable _width myvalue My_Value start date!6
7 C Identifiers Identifiers can be arbitrarily long: int myidentifierisreallyreallyreallylongfornoreason; Some compilers do not consider two identifiers to be different unless they vary somewhere within the first 31 characters. Thus, the following two identifiers might be considered the same: myidentifierisreallyreallyreallylongfornoreason1 myidentifierisreallyreallyreallylongfornoreason2 C is case sensitive: counter, Counter and COUNTER are all different identifiers!7
8 C Identifiers Important to distinguish between rules of the language and naming conventions Rules of the language (syntax): enforced by the compiler Naming conventions: commonly used guidelines that are typically a matter of style, but not enforced by the compiler!8
9 Naming Conventions Choose names that are (human) readable and meaningful, such as count or width (rather than c or w) Makes it easier to follow the code and remember what variable to use later in your code Short names are sometimes okay: Counters: i,j,k Math equations: x,y,z Variables: Begin with a lowercase letter e.g., grades, bank_balance Multiword names use underscores between words e.g., class_average!9
10 Variables and Values Variables are memory locations that store data (e.g., numbers, letters, etc.) The data stored by a variable is called its value The value of a variable can be changed Variables must be declared before they can be used Declaration tells the compiler the variable names and the type of information they will store (e.g., the data type) double myname; variable data type int counter; variable name!10
11 Variables and Values #include <stdio.h> Output: If you have 6 cows per barn int main(void) { int barns, cowsper, totalcows; barns = 10; cowsper = 6; totalcows = barns * cowsper; and 10 barns, then the total number of cows is 60 variable declarations variable initialization/assignment } printf("if you have %d cows per barn \n", cowsper); printf("and %d barns, then\n", barns); printf("the total number of cows is %d.\n", totalcows); return 0;!11
12 Variables and Values Variables: b a r n s c o w s P e r t o t a l C o w s When you declare a variable, you provide its name and type: int barns, cowsper, totalcows; Can be declared separately: i n t barns; i n t cowsper; i n t totalcows; Assigning values (variable must be declared before use) barns = 10; cowsper = 6; totalcows = barns * cowsper;!12
13 Syntax and Examples A variable s type determines what kind of value it can store (e.g., real numbers, characters, integers, etc.) Examples: int x, y, i, j; double balance, interestrate; char jointorindividual; A variable is typically declared at the beginning of main: int main(void) {  declare variables here : } Variables must be declared and initialized before they are used!13
14 Types in C In most programming languages, a type implies several things: A set of possible values A (hardware) representation for those values A set of operations on those values Example: type int Values: 2 bytes: integers in the range 32,768 to 32,767 4 bytes: 2,147,483,648 to 2,147,483,647 Representation: 2 or 4 bytes, binary Operations: addition (+), subtraction (), multiplication (*), division (/), and remainder (%)!14
15 Data Types in C Primitive types (a.k.a. standard types): Values are simple, nondecomposable values such as a number (not a digit) or character can be variables or constants each primitive type has a set range of values it may represent used as abstractions for data: int represents whole numbers double represents real numbers (decimals) char represents a single character void represents and empty set (e.g., it stores null)!15
16 Examples of Primitive Values Integer values: Floating point values: e e5 Character values (enclosed in single quotes): a A % Values such as the above are often referred to as constants or literals!16
17 More Primitive Types Integer types: int (arguably the most commonly used) Two floatingpoint types: float double (again, arguably the most common) One character type: char
18 Data Type Qualifiers Data type qualifiers are used with primitive types to alter their range (e.g., the numbers or characters they can represent) and storage space requirements C data type qualifiers (not used for floats): signed unsigned Thus, we can declare a signed int or an unsigned int
19 Integer Data Types C Integer Data Types Memory Used Size Range * short 2 bytes 32,768 to 32,767 signed short 2 bytes 32,768 to 32,767 unsigned short 2 bytes 0 to 65,535 int 4 bytes 2,147,483,648 to 2,147,483,647 signed int 4 bytes 2,147,483,648 to 2,147,483,647 unsigned int 4 bytes 0 to 4,294,967,295 long signed long 8 bytes 8 bytes 9,223,372,036,854,775,808 to 9,223,372,036,854,775,8079,223,372,036,854,775,808 to 9,223,372,036,854,775,807 unsigned long 8 bytes 0 to <a really big number> * These are HIGHLY dependent on the compiler and processor used.!19
20 Floating Point Data Types C Floating Point Data Types Memory Used Size Range float 4 bytes 3.4E37 to 3.4E+38 double 8 bytes 1.7E307 to 1.7E+308 long double 10 bytes 3.4E4931 to 1.1E+4932!20
21 Why Different Types of Numbers? Operations can be faster using integers rather than doubles Some types use less memory, which may be important in large or complex programs Rounding errors may occur if the wrong data type is used (e.g., using an int when you need a double)
22 Character Data Types C Character Data Types Memory Used Size Range char 1 byte 128 to 127 signed char 1 byte 128 to 127 unsigned char 1 byte 0 to 255 chars are represented as integers through the use of the ASCII character set not useful for languages that use alternative alphabets see
23 Literals Values such as 2, 3.7 or 'y' are called constants or literals Integer literals can be preceded by a + or sign, but cannot contain commas Every integer literal is of type int (or one of its qualified variants such as short int) The type of an integer literal can be determined by inspection (e.g., by looking at it!)!23
24 Floating Point Literals Floating point literals can also be preceded by a + or sign, but cannot contain commas There are two distinct properties that every floating point literal has: format: either fully expanded notation or scientific notation type: either float, double, or long double Both the format and the type of a floating point literal can be determined by inspection (i.e., by looking at it)!24
25 Assignment Statements An assignment statement is used to assign a value to a variable int answer; answer = 42; variable declaration assignment statement The equals sign (=) is called the assignment operator Before assignment: After assignment: barns?? barns 10 cowsper?? cowsper 6 * totalcows?? totalcows 60!25
26 Expression Data Types The data type of an arithmetic expression depends on the data types of the operands length * width; The result of this expression will be of type: int if both length and width are of type int double if either length or width are of type double mixedtype expression: an expression with operands of more than one data type
27 Assignment Statements Assignment syntax: variable = expression; expression Can Be Example A literal or constant x = 4.3 Another variable An expression that combines variables and literals using operators x = y x = y / 10!27
28 Assignment Compatibilities C is statically typed, which means that there are limitations on mixing variables and values in expressions and assignments int x = 0; long y = 0; double z = 0.0; x = y; /* "legal", but not recommended (overflow) */ x = z; /* "legal", but type converted from float to int) */ y = z; /* "legal", but type converted from float to int) */ z = 3.6; /* legal since 3.6 is by default a double */ y = 25; /* legal, but why? */!28
29 Type Casting (a.k.a Type Conversion) A type cast creates a value of a new type from an original type A type cast can be used to force an assignment when otherwise it would be illegal or autocast by the compiler Example: double distance; distance = 9.0; int points; points = distance; // legal, but will be (auto) cast to an int points = (int)distance; // legal, specifies cast explicitly!29
30 Type Casting The value of (int)distance is 9, but the value of distance both before and after the cast is 9.0 The type of distance does NOT change and remains double What happens if distance contains 9.7? any value to the right of the decimal point is truncated (as opposed to rounded) Remember to cast with care because the results can be unpredictable int x; long z = ; x = (int)z;!30
31 Arithmetic Expressions Much the same as what you learned in math classes, but more precise in expression Rules of operator precedence follow math rules (BEDMAS, PEMDAS, etc.) Assume a = 10 and c = 2. What are the results of the following calculations? b = 4 * a / c  3 b = (4 * a) / c  3 b = 4 * a / (c  3) b = 4 * (a / c)  3
32 Arithmetic Operators Operator Meaning Examples + addition  subtraction * multiplication / division % modulus (remainder) is is is is * 4.0 is * 4 is / 4.0 is / 4 is 1 6 % 2 is 0 7 % 2 is 1
33 Arithmetic Operators Operators have operands, which are literals, variables or subexpressions Expressions with two or more operators can be viewed as a series of steps, each involving only two operands The result of one step produces an operand that is used in the next step Most of the basic math rules of precedence apply C is leftassociative for arithmetic operations
34 Arithmetic Operations Example: int x = 0, y = 50, z = 20; double balance = 50.25, rate = 0.05; x = x + y + z; balance = balance + balance * rate; balance = (balance + balance) * rate;!34
35 Expression Type A single expression can contain operands of both double and int types In that case, the type of the resulting expression is double int hoursworked = 40; double payrate = 8.25; double totalpay; Then the expression in the assignment: totalpay = hoursworked * payrate; results in a double with a value of If the variable totalpay is of type int, then the above statement results in an int with value 330. Why?!35
36 The Division Operator The division operator ( / ) behaves as expected If at least one of the operands is of type double, then the result is also of type double: 9.0 / 2 = / 2.0 = / 2.0 = / 2 = 5.0 If both operands are of type int, then the result is truncated (not rounded) and of type int: 9 / 2 = 4 99 / 100 = 0!36
37 The Division Operator The rules on the previous slide are true regardless of whether the operands are literals, variables, or more general expressions int x = 40; int y = 7; double z = 8.25; double w = 2.5; If at least one of the operands is of type double, then the result is also of type double: z / x = y / 2.5 = 2.8 y / w = 2.8 (y + 1) / w = 3.2 If both operands are of type int, then the result is truncated (not rounded) and of type int: x / y = 5 (x + 1) / 8 = 5 x / 7 = 5!37
38 The mod Operator The mod ( % ) operator is used with operands of integer type to obtain the remainder after integer division 14 divided by 4 is 3 with a remainder of 2: In other words: 14 % 4 is equal to 2 The mod operator has many uses, including determining: If an integer is odd or even: x % 2 = 0 If one integer is evenly divisible by another integer: a % b = 0 Mapping a large number of m items, number 1 through m, into n>=2 groups or buckets!38
39 Unary Operators A unary operator takes only one operand C is rightassociative for unary operators Operand Meaning Example! Logical Negation  Unary Minus 4 + Unary Plus +4!1 = 0!0 = 1 ++<variable> preincrement ++x <variable>++ postincrement x++ <variable> predecrement x <variable postdecrement x
40 Operator Precedence Parentheses first, from inside out Operator precedence: unary operators are first (from right to left) *, /, % are second (from left to right) binary + and  are last (from left to right) Use parentheses to force the order you wish to have
41 Numerical Inaccuracies Representational Error: a.k.a roundoff error when a floating point number cannot be represented exactly because a double or float has only a fixed number of decimal places Cancellation Error: when adding very small number to larger numbers, the decimal places may be truncated, thus removing the influence of the small number = may be represented as on some computers
42 Numerical Inaccuracies Arithmetic Underflow: when a value is too small to be represented accurately, it is represented (incorrectly) as 0 Arithmetic Overflow: when a value is too large to be represented accurately has to do with how the number is represented in binary
Primitive Types. Four integer types: Two floatingpoint types: One character type: One boolean type: byte short int (most common) long
Primitive Types Four integer types: byte short int (most common) long Two floatingpoint types: float double (most common) One character type: char One boolean type: boolean 1 2 Primitive Types, cont.
More informationCOMP Primitive and Class Types. Yi Hong May 14, 2015
COMP 110001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to
More informationObjectives. 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
More informationChapter 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
More informationChapter 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
More informationLESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:
LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words
More informationComputer System and programming in C
1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign
More informationLECTURE 3 C++ Basics Part 2
LECTURE 3 C++ Basics Part 2 OVERVIEW Operators Type Conversions OPERATORS Operators are special builtin symbols that have functionality, and work on operands. Operators are actually functions that use
More informationCS102: Variables and Expressions
CS102: Variables and Expressions The topic of variables is one of the most important in C or any other highlevel programming language. We will start with a simple example: int x; printf("the value of
More informationThese are reserved words of the C language. For example int, float, if, else, for, while etc.
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 a sequence of letters and digits, but must start with a letter.
More informationBasics 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
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 21 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationOperators. Lecture 3 COP 3014 Spring January 16, 2018
Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special builtin symbols that have functionality, and work on operands operand an input to an operator Arity  how many operands an operator
More informationFundamentals of Programming
Fundamentals of Programming Lecture 3  Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables
More informationWill introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators
Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships
More informationOperators and Expressions:
Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine
More informationDeclaration and Memory
Declaration and Memory With the declaration int width; the compiler will set aside a 4byte (32bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier
More informationC++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.
EEE117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic
More informationReserved Words and Identifiers
1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the
More informationArithmetic Expressions in C
Arithmetic Expressions in C Arithmetic Expressions consist of numeric literals, arithmetic operators, and numeric variables. They simplify to a single value, when evaluated. Here is an example of an arithmetic
More informationWork 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
More informationFundamental 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
More informationObjectives. 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
More informationCS16 Week 2 Part 2. Kyle Dewey. Thursday, July 5, 12
CS16 Week 2 Part 2 Kyle Dewey Overview Type coercion and casting More on assignment Pre/post increment/decrement scanf Constants Math library Errors Type Coercion / Casting Last time... Data is internally
More informationExpressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators
Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical
More informationprintf( Please enter another number: ); scanf( %d, &num2);
CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationCSc 10200! Introduction to Computing. Lecture 23 Edgardo Molina Fall 2013 City College of New York
CSc 10200! Introduction to Computing Lecture 23 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
More informationChapter 2: Using Data
Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time
More informationBasic Computation. Chapter 2
Basic Computation Chapter 2 Outline Variables and Expressions The Class String Keyboard and Screen I/O Documentation and Style Variables Variables store data such as numbers and letters. Think of them
More informationOverview (4) CPE 101 mod/reusing slides from a UW course. Assignment Statement: Review. Why Study Expressions? D1
CPE 101 mod/reusing slides from a UW course Overview (4) Lecture 4: Arithmetic Expressions Arithmetic expressions Integer and floatingpoint (double) types Unary and binary operators Precedence Associativity
More informationChapter 2: Introduction to C++
Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson AddisonWesley Education, Inc. Publishing as Pearson AddisonWesley 2.1 Parts of a C++
More informationANSI 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
More informationChapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, AddisonWesley Inc. Publishing as Pearson AddisonWesley
More informationProgramming 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()
More informationCS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation
CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;
More informationProgramming in C++ 5. Integral data types
Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long
More informationITP 342 Mobile App Dev. Code
ITP 342 Mobile App Dev Code Comments Variables Arithmetic operators Format specifiers if  else Relational operators Logical operators Constants Outline 2 Comments For a single line comment, use // The
More informationLecture 3. More About C
Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 31 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants
More information2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants
Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a
More informationChapter 2 Basic Elements of C++
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 21 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion
More informationModule 2  Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1
Module 2  Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions
More informationMODULE 02: BASIC COMPUTATION IN JAVA
MODULE 02: BASIC COMPUTATION IN JAVA Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment
More informationData and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence
Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public
More informationDATA TYPES AND EXPRESSIONS
DATA TYPES AND EXPRESSIONS Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment Mathematical
More informationBasic Operations jgrasp debugger Writing Programs & Checkstyle
Basic Operations jgrasp debugger Writing Programs & Checkstyle Suppose you wanted to write a computer game to play "Rock, Paper, Scissors". How many combinations are there? Is there a tricky way to represent
More information3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.
3. EXPRESSIONS It is a sequence of operands and operators that reduce to a single value. Operator : It is a symbolic token that represents an action to be taken. Ex: * is an multiplication operator. Operand:
More informationThe C++ Language. Arizona State University 1
The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationISA 563 : Fundamentals of Systems Programming
ISA 563 : Fundamentals of Systems Programming Variables, Primitive Types, Operators, and Expressions September 4 th 2008 Outline Define Expressions Discuss how to represent data in a program variable name
More informationReview: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements
Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja
More informationBy the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program
1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a generalpurpose, highlevel 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
More informationOn a 64bit CPU. Size/Range vary by CPU model and Word size.
On a 64bit CPU. Size/Range vary by CPU model and Word size. unsigned short x; //range 0 to 65553 signed short x; //range ± 32767 short x; //assumed signed There are (usually) no unsigned floats or doubles.
More informationCS112 Lecture: Primitive Types, Operators, Strings
CS112 Lecture: Primitive Types, Operators, Strings Last revised 1/24/06 Objectives: 1. To explain the fundamental distinction between primitive types and reference types, and to introduce the Java primitive
More informationC: 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
More informationBASIC ELEMENTS OF A COMPUTER PROGRAM
BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators
More informationLecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value
Lecture Notes 1. Comments a. /* */ b. // 2. Program Structures a. public class ComputeArea { public static void main(string[ ] args) { // input radius // compute area algorithm // output area Actions to
More informationCMPT 125: Lecture 3 Data and Expressions
CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,
More informationOutline. Data and Operations. Data Types. Integral Types
Outline Data and Operations Data Types Arithmetic Operations Strings Variables Declaration Statements Named Constant Assignment Statements Intrinsic (Builtin) Functions Data and Operations Data and Operations
More informationLECTURE 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
More information2. Numbers In, Numbers Out
COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break
More informationChapter 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
More informationData 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
More informationOverview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University
Overview of C, Part 2 CSE 130: Introduction to Programming in C Stony Brook University Integer Arithmetic in C Addition, subtraction, and multiplication work as you would expect Division (/) returns the
More informationNumerical Data. CS 180 Sunil Prabhakar Department of Computer Science Purdue University
Numerical Data CS 180 Sunil Prabhakar Department of Computer Science Purdue University Problem Write a program to compute the area and perimeter of a circle given its radius. Requires that we perform operations
More informationDEPARTMENT OF MATHS, MJ COLLEGE
T. Y. B.Sc. Mathematics MTH 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,
More informationCOMP 110 Introduction to Programming. What did we discuss?
COMP 110 Introduction to Programming Fall 2015 Time: TR 9:30 10:45 Room: AR 121 (Hanes Art Center) Jay Aikat FB 314, aikat@cs.unc.edu Previous Class What did we discuss? COMP 110 Fall 2015 2 1 Today Announcements
More informationUNIT 3 Introduction to C++
UNIT 3 Introduction to C++ C++ Character Sets: Letters AZ, az Digits 09 Special Symbols Space +  * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationObjectives. Data Types (continued) Data Types 4. การเข ยนโปรแกรมพ นฐาน ว ทยาการคอมพ วเตอร เบ องต น Fundamentals of Computer Science
204111 ว ทยาการคอมพ วเตอร เบ องต น Fundamentals of Computer Science ภาคการศ กษาท ภาคการศกษาท 1 ป ปการศกษา การศ กษา 2556 4. การเข ยนโปรแกรมพ นฐาน 4.2 ต วแปร น พจน และการก าหนดค า รวบรวมโดย อ. ดร. อาร ร
More information2. Numbers In, Numbers Out
REGZ9280: Global Education Short Course  Engineering 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. REGZ9280 14s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write
More informationSlide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng
Slide Set 2 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 2 slide
More informationCS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University
CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can
More informationUnit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School
Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions Mr. Dave Clausen La Cañada High School Vocabulary Variable A variable holds data that can change while the program
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationMidterms Save the Dates!
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Primitive Data Types Arithmetic Operators Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.12.5, Ch 4.14.2.
More information9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C
Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments
More informationCHAPTER 3 BASIC INSTRUCTION OF C++
CHAPTER 3 BASIC INSTRUCTION OF C++ MOHD HATTA BIN HJ MOHAMED ALI Computer programming (BFC 20802) Subtopics 2 Parts of a C++ Program Classes and Objects The #include Directive Variables and Literals Identifiers
More informationCharacter Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits
More informationBASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I
BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment
More informationFundamentals of C. Structure of a C Program
Fundamentals of C Structure of a C Program 1 Our First Simple Program Comments  Different Modes 2 Comments  Rules Preprocessor Directives Preprocessor directives start with # e.g. #include copies a file
More informationObjects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003
Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void
More informationA Java program contains at least one class definition.
Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public
More informationThe C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)
The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments
More informationLesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions  Copyright Denis Hamelin  Ryerson University
Lesson #3 Variables, Operators, and Expressions Variables We already know the three main types of variables in C: int, char, and double. There is also the float type which is similar to double with only
More informationChapter 4: Basic C Operators
Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional
More informationChapter 2. Lexical Elements & Operators
Chapter 2. Lexical Elements & Operators ByoungTak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr The C System
More informationLecture 3 Tao Wang 1
Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers
More informationProgram Fundamentals
Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java
More informationProgramming 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
More informationProgramming in C++ 6. Floating point data types
Programming in C++ 6. Floating point data types! Introduction! Type double! Type float! Changing types! Type promotion & conversion! Casts! Initialization! Assignment operators! Summary 1 Introduction
More informationDifferentiate Between Keywords and Identifiers
History of C? Why we use C programming language Martin Richards developed a highlevel computer language called BCPL in the year 1967. The intention was to develop a language for writing an operating system(os)
More informationTOPIC 2 INTRODUCTION TO JAVA AND DR JAVA
1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationA 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
More informationChapter 3. Fundamental Data Types
Chapter 3. Fundamental Data Types ByoungTak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr Variable Declaration
More informationBasics 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
More informationData types, variables, constants
Data types, variables, constants 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 in C 2.6 Decision
More informationChapter 12 Variables and Operators
Chapter 12 Variables and Operators Highlights (1) r. height width operator area = 3.14 * r *r + width * height literal/constant variable expression (assignment) statement 122 Highlights (2) r. height
More informationFundamental 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
More informationUNIT  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 generalpurpose programming language. It has been
More information