Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Similar documents
ANSI C Reserved Words

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

CS349/SE382 A1 C Programming Tutorial

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

6.096 Introduction to C++ January (IAP) 2009

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Lecture 02 C FUNDAMENTALS

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Fundamentals of Programming

DEPARTMENT OF MATHS, MJ COLLEGE

ET156 Introduction to C Programming

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

C: How to Program. Week /Mar/05

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Chapter 2 - Introduction to C Programming

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

XSEDE Scholars Program Introduction to C Programming. John Lockman III June 7 th, 2012

Programming. C++ Basics

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

A Fast Review of C Essentials Part I

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Data Types and Variables in C language

Presented By : Gaurav Juneja

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Procedures, Parameters, Values and Variables. Steven R. Bagley

BLM2031 Structured Programming. Zeyneb KURT

Introduction to the C Programming Language

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE

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

Chapter 21: Introduction to C Programming Language

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

Introduction to Computing Lecture 01: Introduction to C

Chapter 1 & 2 Introduction to C Language

Fundamental of Programming (C)

ANSI C Reserved Words. Abstract Data Type: complex. Arrays. Multimedia Programming Lecture 5

CMPE-013/L. Introduction to C Programming

Chapter 2: Overview of C. Problem Solving & Program Design in C

!"#$% &'($) *+!$ 0!'" 0+'&"$.&0-2$ 10.+3&2),&/3+, %&&/3+, C,-"!.&/+"*0.&('1 :2 %*10% *%7)/ 30'&. 0% /4%./

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Variables. Data Types.

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

CS 61C: Great Ideas in Computer Architecture Introduction to C

Review of the C Programming Language for Principles of Operating Systems

Fundamental of C programming. - Ompal Singh

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

Programming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester

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

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

CMSC 104 -Lecture 5 John Y. Park, adapted by C Grasso

Syntax and Variables

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5

Programming and Data Structures

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

CHW 469 : Embedded Systems

C - Basics, Bitwise Operator. Zhaoguo Wang

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

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

CMSC 246 Systems Programming

Lecture 2: C Programming Basic

Introduction to Programming

Lecture 3. More About C

Review of the C Programming Language

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Data Type Fall 2014 Jinkyu Jeong

Structures and Pointers

Variables in C. CMSC 104, Spring 2014 Christopher S. Marron. (thanks to John Park for slides) Tuesday, February 18, 14

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

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

ET156 Introduction to C Programming

CS2141 Software Development using C/C++ C++ Basics

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Princeton University COS 333: Advanced Programming Techniques A Subset of C90

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

Beginning C Programming for Engineers

BBM 101 Introduc/on to Programming I Fall 2014, Lecture 3. Aykut Erdem, Erkut Erdem, Fuat Akal

OBJECT ORIENTED PROGRAMMING

In this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.

Tokens, Expressions and Control Structures

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

Introduction to C++ Systems Programming

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Quick Reference Guide

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

Matlab? Chapter 3-4 Matlab and IPT Basics. Working Environment. Matlab Demo. Array. Data Type. MATLAB Desktop:

The Design of C: A Rational Reconstruction: Part 2

COMP322 - Introduction to C++

CSCE 110 PROGRAMMING FUNDAMENTALS

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Quick Reference Guide

Continued from previous lecture

Chapter 15 - C++ As A "Better C"

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1

VARIABLES AND CONSTANTS

Structured Programming. Jon Macey

Transcription:

Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine final grade Assignments and other materials available on the site: www.liacs.nl/~erwin/mmp2004 Assignment work should be posted on the Bulletin Board C++ ANSI C standard definition (1983-1989) C++ Compiling 1. C++ code 2. Compilation 3. Object code 4. Linking 5. Executable ANSI C Reserved Words auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while 1

I/O, Expressions and Statements Types and Variables Formatted I/O <stdio.h> printf( Text with format control %s,stringvar) scanf( %d,integervar) Output streams <iostream.h> #include <iostream.h> cout << Hello World\n ; cin >> number1 >> number2; Expressions and Statements a+b 1 x=p+d 38/5 39%4 (is equal to mod) a = a +1 a += 1 a *=3 a++ ++a a-- --a Statements i=3; b = (i++); c = (++i); (after this statement: b = 3 and c = 5) char (1 byte) short (short int) (2 byte) int (2 or 4 bytes) enum (2 or 4 bytes) long (long int) (4 bytes) float (4 bytes) double (8 bytes) long double (10 bytes) unsigned and signed to indicate the use of a sign in the number boolean type bool, 0 = false, 1 = true Types and Variables int n=100; declaration and definition int n; declaration only const int i = 5; // n is not allowed to change i = 10; // Error i++; // Error volatile is the opposite of const but varies amongst systems float number; enum days Sunday, Monday,Tuesday, Wednesday, Thursday, Friday, Saturday today; today = Monday; Special Keywords register int a To indicate that a, if possible should be placed in a register (very fast memory) of the CPU, because a is intensively used 2

Operators logical: <, >, <=, >=, ==,!=, &&,,! arithmetic: +, *, -, /, %, --, ++, sizeof,, bitwise: &,, ^ (XOR), ~(negation), << (shift left), >> (shift right) (bitoperations) +=, -=, *=, /=, %=, &=, =, ^=, <<=, >>= Special Statements Conditional Statements if (expression) statement else statement Iterative Statements while (expression) do statement do statement while (expression); for (expr1; expr2; expr3) statement Switch Statement switch (expression) statement Break and Continue statement: a = x+1; compound statement: a=x+1; b=3; while (boolean expression) do.; break; ; continue;.. next statement; break interrupts the loop and continues with next statement; continue interrupts the loop and continues with boolean expression Structuring Your Program Pseudo Code Calculator Example: while (continue) do read operand1 read operator read operand2 calculate result print result od 3

Structuring Your Program Top Down function continu return true if continue return false if end function calculate return result = operand1 (operator) operand2 function read_operator main program while (continue) do read operand1 (scanf function from standard lib) read operator read operand2 (scanf function from standard lib) calculate result print result (printf function from standard lib) od Functions In C only functions Parameters by value Function definitions never within other functions #include <stdio.h> #include <math.h> int main(void) // Declaration of the function times int times(int x, int y); cout << times(x,y) << sin(times(x,y)) << \n ; return 0; // Definition of the function times int times(int x; int y) int result; result = x*y; return result; Functions void print_header(void) No parameters, no results int main(void) No parameters, result an int int smallest(int x, int y, int z) Three integer parameters and result int Functions Recursion int power(int x, int exponent) if (exponent == 0) return 1; else return x * power( x, exponent 1 ); 4

Functions: Parameters by Value void swap(int x, int y) int temp; temp = y; y = x; x = temp; void main(void) int a =10, b = 11; swap(a,b); Parameters are given by value: x and y can be seen as local variables that are initialized at the call of the function After swap(a,b) executed, the variables a and b passed through the parameters will still have their original values, as only their respective values have been passed to the local int x and int y! 5