C++ Programming Basics
|
|
- Roxanne Curtis
- 6 years ago
- Views:
Transcription
1 C++ Programming Basics Chapter 2 and pp Copyright Delroy A. Brinkerhoff. All Rights Reserved. CS 1410 Chapter 2 Slide 1 of 25
2 Program Components Function main P Every C/C++ program has exactly one function named main < main is not a keyword but should be treated as if it was < main is where the (apparent) program execution begins (it is called by the system) PFunctions have 4 parts < Name < Return value type < Argument list < Body { } int main ( ) body (a block ) return value type name argument list header CS 1410 Chapter 2 Slide 2 of 25
3 Pre-Opened Console Files Pre-opened I/O files available to Console-mode programs PInput < cin >> var; POutput < cout << exp; P Error reporting < cerr << exp; Pcin, cout, and cerr are library objects keyboard standard in stdin cin program screen standard error stderr cerr screen standard out stdout cout CS 1410 Chapter 2 Slide 3 of 25
4 The C/C++ Preprocessor Simple text manipulation P Traditionally, a program (cpp) that ran before the compiler < Functionality may be merged with modern compilers (-E terminates compilation after preprocessing a file) < Performs textual replacement before compilation begins P Processes directives that begin with # < #include <iostream> < and > indicate system header files (located in the include directory) < #include myprog.h " and " indicate program header files located in the current directory < #define line_length 100 nemonic for magic numbers and strings consistency (one place for change) CS 1410 Chapter 2 Slide 4 of 25
5 The Preprocessor In Action Substitutes and copies text #define SIZE 100 other stuff preprocessor iostream stuff compiler prog.h other stuff #include <iostream> #include "prog.h" using namespace std; void main( ) { cout << SIZE; } prog.cpp iostream void main( ) { cout << 100; } temporary file CS 1410 Chapter 2 Slide 5 of 25
6 Compiling Programs Multi-file programs source code compiler object files libraries editor linker executable runtime.cpp.c CS 1410 Chapter 2 Slide 6 of 25.obj.o
7 Basic Data Types Type Specifiers PData types < void 0 bytes no value < char 1 byte -128 to 127 or 0 to 255 < short 2 bytes -32,767 to 32,767 < int 2 to 4 bytes -2,147,483,648 to 2,147,483,647 < long 4 bytes -2,147,483,648 to 2,147,483,647 < bool int false / true < float 4 bytes ± ±38 (6-7 sig digs) < double 8 bytes ± ±308 (~15 sd) < long double 16 bytes not universally supported P Ambiguities < The size of an int is the machine s word size < The only garentee is short # int # long < char is signed on some machines and unsigned on others P Most compilers use IEEE format for floating point numbers CS 1410 Chapter 2 Slide 7 of 25
8 Definitions and Declarations Important vocabulary terms P Definitions allocate memory < Variables: int counter; < Functions: double sqrt(double x) {... } P Declarations introduce a name, identifier, or symbol to the compiler (the name is placed in the compiler s symbol table) < Variables: extern int counter; < Functions: double sqrt(double x); // in <cmath> PA definition may also serve as a declaration CS 1410 Chapter 2 Slide 8 of 25
9 Type Conversions Implicit and Explicit Pchars and ints convert back and forth P Small types automatically promoted to large types in arithmetic expressions PIf a and b are ints, a/b is an int (truncates if necessary) P Explicit conversions are called type casts: (type)expression < Required to convert from a large type to a small type and to force conversions for / < int i = (int) ; // always truncates < int i = (int)( ); < unsigned int i = (unsigned int) 75; < double x = (double) 1 / 3; CS 1410 Chapter 2 Slide 9 of 25
10 Identifier Names (i.e., Symbols) Variables, functions, structures, classes, etc. PRules < May be any length < Are case sensitive < Must begin with a letter, which includes an underscore (_) < Subsequent characters may be letters, digits, and underscores < Cannot be a keyword < May only be defined once in a scope < Should avoid library names < Must be declared before use < Must be defined exactly once CS 1410 Chapter 2 Slide 10 of 25
11 Expression and Statement Overview The Building Blocks - vocabulary terms P C++ is an imparative language PExpressions produce a value < Constant < Variable < Function call (returning a value not void) < Grouping of the above combined with operators < Form r-values (allowed on the RHS =): y + z or sqrt(y) or n > 100 PStatements form a complete unit of work are instructions < Are terminated with a semicolon (;) < May span lines or may be more than one on a line < Function call (not returning a value or value ignored) < Assignment statements: x = y + z; or p = sqrt(y); < Compound (or block) statements are formed of simple statements between { and } (block is not terminated with a semicolon) CS 1410 Chapter 2 Slide 11 of 25
12 Variables Name a region of memory where data is stored PMust be defined before use: includes data type and name P Names are case sensitive PExamples (definition and initialization) < int dollars; < int quarters, dimes, nickels, pennies; < int money = 217; < double x, pi = ; < char begin = 'A', end = 'Z', newline = '\n'; int i; i undefined 0x0a i is unitialized i = 10; i 10 0x0a i is 10 CS 1410 Chapter 2 Slide 12 of 25
13 Variables: Address vs Content Address is intrinsic, content may change PA left value (aka l-value) < is a value that can be on the left hand side of = < is the address of a variable PA right value (aka r-value) < is a value that can be on the right hand side of = < can be any valid expression i = // i represents the address of i (l-value or 0xffffff00) = i // i represents the content of i (r-value or 73) i 73 0xffffff00 CS 1410 Chapter 2 Slide 13 of 25
14 Variable Modifiers C/C++ Keywords P signed P unsigned P long P short Pauto Pstatic little used- turns unsigned char into signed char (the signedness of char is machine and/or implementation defined) no negative values (doubles the magnitude; often used with bit-manipulation operators; unsigned arithmetic does not overflow) long int is usually just called long short int is usually just called short never used except to illustrate that it can be used (i.e., auto is the default access specifier) local static variables maintain values between function invocation CS 1410 Chapter 2 Slide 14 of 25
15 Constants Types and Examples Pchar 'x' // single quote is a char P String "x" // double quote is a string P String "Hello World" Pint < Decimal < unsigned int 123U < long int L < Octal 0377 unsigned only < Hexadecimal 0xff 0xFF unsigned only P float/double e-24 P long double 2.74e145L // uncommon P Explicit float F CS 1410 Chapter 2 Slide 15 of 25
16 Special Character Constants Backslash Characters P Digraphs represent a single character P\n new line P\t horizontal tab P\0 null (terminates strings) P\b back space P\f form feed P\r carriage return P\a alert (i.e., bell) P\" double quote P\' single quote P\\ backslash P\ddd octal number P\xff hexadecimal number P"Hello\tWorld\n" < The compiler automatically places a \0 after the \n CS 1410 Chapter 2 Slide 16 of 25
17 Operators Precedence and Associativity Operator [ ]., -> (dot and arrow) ( ) ++, --! ~ +, - ( ) & * sizeof Description indexing member selectio n function invocation auto increment and decrement logical negation bitwise complement unary grouping and casting address off indirection or dereference size of variable or type *, /, % multiplication, division, modulo º CS 1410 Chapter 2 Slide 17 of 25 Assoc º º º»»»»»»»»
18 Operators Continued +, - addition and subtraction º << >> bitwise left shift bitwise right shift (sign extend) <, >, <=, >= logical relationships º ==,!= logical equality or inequality º & bitwise and º ^ bitwise exclusive-or º bitwise or º && logical and º logical or º?: conditional expression º =, +=, -=, *=, /=, %=, <<=, >>=, &=, =, ^= operation and assignment (target must be a variable or l-value) CS 1410 Chapter 2 Slide 18 of 25 º º»
19 Operator Examples Unusual operators P Multiple assignment (i.e., the = operator returns a value) < i = j = k = 0; /* equivalent to i = (j = (k = 0)) */ < while ((c = getc( ))!= -1) P Auto increment and decrement < Target must be a variable (i.e., an l-value) < int i, j =10; < i = j++; /* i is 10, j is 11 */ < i = ++j; /* i is 11, j is 11 */ < i = j--; /* i is 10, j is 9 */ < i = --j; /* i is 9, j is 9 */ < i++, ++i, i--, and --i are legal (i.e., assignment is not required) < May be embedded in expressions < Often used in array indexes CS 1410 Chapter 2 Slide 19 of 25
20 Auto Increment / Decrement Understanding the shortcuts x = 10; Operator Meaning Result a = x++; a = x; a == 10 x = x + 1; x == 11 a = ++x; x = x + 1; a == 11 a = x; x == 11 a = x--; a = x; a == 10 x = x - 1; x == 9 a = --x; x = x - 1; a == 9 a = x; x == 9 CS 1410 Chapter 2 Slide 20 of 25
21 Operation with Assignment More unusual operators Pop= (+=, -=, *=, /=, %=, ~=, <<=, >>=) < variable op= expression; ø variable = variable op expression; < x += 10; ø x = x + 10; < i -= 2; ø i = i -2; < a /= b; ø a = a / b; < index %= size; ø index = index % size; < mask <<= 2; ø mask = mask << 2; CS 1410 Chapter 2 Slide 21 of 25
22 Comments Program documentation PC < /* comments go here */ < Can span lines PC++ < /* can use C style comments */ < // comments to the end of the line < Styles can be nested < I use C++ style and save C style to temporarily comment out code /* This style works well for large * commentary before functions */ // Function descriptions can // also be presented in this style /* void func( ) { a = b + c: } */ // comment CS 1410 Chapter 2 Slide 22 of 25
23 Test Cases and Program Validation The first step in test driven programming PA test case consists of at least two values: < Input value < Correct output value for the input < Long calculations may require one or more intermediate values PA set of test cases tests the behavior of the program with < Correct input < Incorrect input < Boundary values if appropriate Boundary values are on the boundary between correct and incorrect Many errors occur near or on boundary values double c = 5.0 / 9.0 * (f - 32); test cases: input: 32; output 0 input: 30; output: input: 212; output 100 input: 213; output: CS 1410 Chapter 2 Slide 23 of 25
24 Test Driven Programming AKA Test Driven Development PUnit tests < Are often but not always automated < They test the functionality of individual parts of a system PA unit test is a set of test cases P When practicing test driven programming / development, programmers create the unit test before writing any code PUnder what conditions can the code fail? P Programming is finished when the programmer cannot think of and test for any more failure conditions CS 1410 Chapter 2 Slide 24 of 25
25 Programming Style Only one rule: MAKE IT READABLE P Compiler ignores indentation and blank lines P Long statements may span multiple lines PMultiple statements may be placed on one line P Recomendations: < One definition / declaration per line < One statement per line < Keep lines short enough that they fit on the screen or printed page < Let physical layout reflect logical construction ( pretty printing ) < Use indentation consistently (use a single editor if possible) < Use blank lines to separate code into logical units; more space for more logically separated units < Place braces ( { and } ) consistently CS 1410 Chapter 2 Slide 25 of 25
UNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationOBJECT ORIENTED PROGRAMMING
OBJECT ORIENTED PROGRAMMING LAB 1 REVIEW THE STRUCTURE OF A C/C++ PROGRAM. TESTING PROGRAMMING SKILLS. COMPARISON BETWEEN PROCEDURAL PROGRAMMING AND OBJECT ORIENTED PROGRAMMING Course basics The Object
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 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 informationChapter 2: Introduction to C++
Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++
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, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley
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 informationIntroduction to Programming
Introduction to Programming session 5 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel s slides Sahrif University of Technology Outlines
More information2.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
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 informationOverview 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.
More informationCSc 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
More informationC++ 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
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 informationA First Program - Greeting.cpp
C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout
More informationChapter 1 Introduction to Computers and C++ Programming
Chapter 1 Introduction to Computers and C++ Programming 1 Outline 1.1 Introduction 1.2 What is a Computer? 1.3 Computer Organization 1.7 History of C and C++ 1.14 Basics of a Typical C++ Environment 1.20
More information! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char
Week 1 Operators, Data Types & I/O Gaddis: Chapters 1, 2, 3 CS 5301 Fall 2016 Jill Seaman Programming A program is a set of instructions that the computer follows to perform a task It must be translated
More informationComputer Programming : C++
The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program
More information2 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
More informationLecture 2 Tao Wang 1
Lecture 2 Tao Wang 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common programming errors
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 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 informationOverview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program
Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of
More informationBasic Types, Variables, Literals, Constants
Basic Types, Variables, Literals, Constants What is in a Word? A byte is the basic addressable unit of memory in RAM Typically it is 8 bits (octet) But some machines had 7, or 9, or... A word is the basic
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 informationBITG 1233: Introduction to C++
BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token
More informationFeatures 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
More informationProgramming. C++ Basics
Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++
More information6.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
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 general-purpose programming language. It has been
More informationUNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING
( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types
More informationC++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay
C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming
More informationStructured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:
Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language Dr. Amal Khalifa Lecture Contents: Introduction to C++ Origins Object-Oriented Programming, Terms Libraries and Namespaces
More informationXC 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
More informationVisual C# Instructor s Manual Table of Contents
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
More informationCOMP322 - Introduction to C++ Lecture 02 - Basics of C++
COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.
More informationMaciej Sobieraj. Lecture 1
Maciej Sobieraj Lecture 1 Outline 1. Introduction to computer programming 2. Advanced flow control and data aggregates Your first program First we need to define our expectations for the program. They
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 information! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.
Week 1: Introduction to C++ Gaddis: Chapter 2 (excluding 2.1, 2.11, 2.14) CS 1428 Fall 2014 Jill Seaman Literals A literal represents a constant value used in a program statement. Numbers: 0, 34, 3.14159,
More informationCSC 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
More informationc++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.
Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object
More informationChapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved
Chapter 1 C++ Basics Copyright 2010 Pearson Addison-Wesley. All rights reserved Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment
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 12-2 Highlights (2) r. height
More informationEEE145 Computer Programming
EEE145 Computer Programming Content of Topic 2 Extracted from cpp.gantep.edu.tr Topic 2 Dr. Ahmet BİNGÜL Department of Engineering Physics University of Gaziantep Modifications by Dr. Andrew BEDDALL Department
More informationThis watermark does not appear in the registered version - Slide 1
Slide 1 Chapter 1 C++ Basics Slide 2 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output Program Style
More informationCreating a C++ Program
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an
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 informationJAVA 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
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 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 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 informationChapter 2 Basic Elements of C++
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion
More informationBasic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable
Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is
More informationC 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,
More informationChapter 2: Overview of C++
Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using C++ 6e by Frank L. Friedman and Elliot B. Koffman C++ Background Introduced by Bjarne Stroustrup of AT&T s Bell Laboratories in
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 informationInformatics Ingeniería en Electrónica y Automática Industrial
Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical
More informationC OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure
C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces
More informationHomework #3 CS2255 Fall 2012
Homework #3 CS2255 Fall 2012 MULTIPLE CHOICE 1. The, also known as the address operator, returns the memory address of a variable. a. asterisk ( * ) b. ampersand ( & ) c. percent sign (%) d. exclamation
More informationProgramming with C++ as a Second Language
Programming with C++ as a Second Language Week 2 Overview of C++ CSE/ICS 45C Patricia Lee, PhD Chapter 1 C++ Basics Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives Introduction to
More informationChapter 12 Variables and Operators
Basic C Elements Chapter 12 Variables and Operators Original slides from Gregory Byrd, North Carolina State University! Variables named, typed data items! Operators predefined actions performed on data
More informationInformation Science 1
Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting
More informationComputer Skills (2) for Science and Engineering Students
م رات ب Computer Skills () for Science and Engineering Students وا ا () ا C++ Department of Computer Science Prince Abdullah Bin Ghazi Faculty of Information Technology Prepared by: Dr. Habes Khraisat
More informationFull 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
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 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 informationChapter 2. Outline. Simple C++ Programs
Chapter 2 Simple C++ Programs Outline Objectives 1. Building C++ Solutions with IDEs: Dev-cpp, Xcode 2. C++ Program Structure 3. Constant and Variables 4. C++ Operators 5. Standard Input and Output 6.
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 informationC++ 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:-
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 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 informationUEE1302 (1102) F10: Introduction to Computers and Programming
Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1302 (1102) F10: Introduction to Computers and Programming Programming Lecture 00 Programming by Example Introduction to C++ Origins,
More informationUNIT-2 Introduction to C++
UNIT-2 Introduction to C++ C++ CHARACTER SET Character set is asset of valid characters that a language can recognize. A character can represents any letter, digit, or any other sign. Following are some
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 informationChapter 2. C++ Basics
Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-2 2.1 Variables and Assignments Variables
More informationWeek 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.
Week 2: Console I/O and Operators Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.1) CS 1428 Fall 2014 Jill Seaman 1 2.14 Arithmetic Operators An operator is a symbol that tells the computer to perform specific
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 informationME 461 C review Session Fall 2009 S. Keres
ME 461 C review Session Fall 2009 S. Keres DISCLAIMER: These notes are in no way intended to be a complete reference for the C programming material you will need for the class. They are intended to help
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 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 informationC OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed
C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages
More informationChapter 12 Variables and Operators
Chapter 12 Variables and Operators Basic C Elements Variables Named, typed data items Operators Predefined actions performed on data items Combined with variables to form expressions, statements Statements
More informationTutorial-2a: First steps with C++ programming
Programming for Scientists Tutorial 2a 1 / 18 HTTP://WWW.HEP.LU.SE/COURSES/MNXB01 Introduction to Programming and Computing for Scientists Tutorial-2a: First steps with C++ programming Programming for
More informationCSCE 110 PROGRAMMING FUNDAMENTALS
CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 2. Overview of C++ Prof. Amr Goneid, AUC 1 Overview of C++ Prof. Amr Goneid, AUC 2 Overview of C++ Historical C++ Basics Some Library
More informationCSI33 Data Structures
Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence
More informationCSCI 1061U Programming Workshop 2. C++ Basics
CSCI 1061U Programming Workshop 2 C++ Basics 1 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output
More informationProgramming 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++
More informationComputers 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
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 informationIntroduction to C# Applications
1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making
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 informationProfessor Peter Cheung EEE, Imperial College
1/1 1/2 Professor Peter Cheung EEE, Imperial College In this lecture, we take an overview of the course, and briefly review the programming language. The rough guide is not very complete. You should use
More informationI Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.
I Internal Examination Sept. 2018 Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs. [I]Very short answer questions (Max 40 words). (5 * 2 = 10) 1. What is
More informationIntroduction to C++ Introduction and History. Characteristics of C++
Introduction and History Introduction to C++ Until 1980, C programming was widely popular, and slowly people started realizing the drawbacks of this language and at the same time, the engineers had come
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 informationCSc Introduction to Computing
CSc 10200 Introduction to Computing Lecture 2 Edgardo Molina Fall 2011 - City College of New York Thursday, September 1, 2011 Introduction to C++ Modular program: A program consisting of interrelated segments
More informationC Programming Language (Chapter 2 of K&R) Variables and Constants
C Programming Language (Chapter 2 of K&R) Types, Operators and Expressions Variables and Constants Basic objects manipulated by programs Declare before use: type var1, var2, int x, y, _X, x11, buffer;
More information