Types. C Types. Floating Point. Derived. fractional part. no fractional part. Boolean Character Integer Real Imaginary Complex

Similar documents
Program Flow. Instructions and Memory. Why are these 16 bits? C code. Memory. a = b + c. Machine Code. Memory. Assembly Code.

Type Conversion. and. Statements

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

Types, Variables, and Constants

Arrays. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18

Function I/O. Last Updated 10/30/18

CS240: Programming in C

Variation of Pointers

Function I/O. Function Input and Output. Input through actual parameters. Output through return value. Input/Output through side effects

Lab 3. Pointers Programming Lab (Using C) XU Silei

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

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

Chapter 8: Function. In this chapter, you will learn about

Lecture 3: C Programm

OBJECTIVE QUESTIONS: Choose the correct alternative:

UNIVERSITY OF WINDSOR Fall 2006 QUIZ # 1. Examiner:Ritu Chaturvedi Dated : Oct 3rd, Student Name: Student Number:

Kurt Schmidt. October 30, 2018

Lecture (07) Arrays. By: Dr. Ahmed ElShafee. Dr. Ahmed ElShafee, ACU : Fall 2015, Programming I

Functions in C. Lecture Topics. Lecture materials. Homework. Machine problem. Announcements. ECE 190 Lecture 16 March 9, 2011

CC112 Structured Programming

Lectures 5-6: Introduction to C

C Pointers. 6th April 2017 Giulio Picierro

This exam is to be taken by yourself with closed books, closed notes, no calculators.

CS240: Programming in C

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

Functions in C C Programming and Software Tools

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

CMPE-013/L. Introduction to C Programming

CSC 1600 Memory Layout for Unix Processes"

DECLARAING AND INITIALIZING POINTERS

Pointer Data Type and Pointer Variables

File I/O. Last updated 10/30/18

Compiling Techniques

Final CSE 131B Spring 2004

Memory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)

C introduction: part 1

Type Definition. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18

CSE 5A Final Fall 2006

Functions. printf( %f cubed is %f,x,cube(x)); return 0; } return parameter type double cube(double var) { return (var*var*var);

Lexical and Syntax Analysis. Abstract Syntax

Flow Chart. The diagrammatic representation shows a solution to a given problem.

This is CS50. Harvard University Fall Quiz 0 Answer Key

AMCAT Automata Coding Sample Questions And Answers

a data type is Types

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science

C Introduction. Comparison w/ Java, Memory Model, and Pointers

G Programming Languages - Fall 2012

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

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

More Arrays. Last updated 2/6/19

Fall 2015 COMP Operating Systems. Lab #3

Jagannath Institute of Management Sciences Lajpat Nagar. BCA II Sem. C Programming

Midterm CSE 131B Spring 2005

Functions. Systems Programming Concepts

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

Lecture 2: C Programm

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

Question 2. [5 points] Given the following symbolic constant definition

General Syntax. Operators. Variables. Arithmetic. Comparison. Assignment. Boolean. Types. Syntax int i; float j = 1.35; int k = (int) j;

Functions BCA-105. Few Facts About Functions:

Programming in C. What is C?... What is C?

EC 413 Computer Organization

Programming in C. What is C?... What is C?

Contents. 8-1 Copyright (c) N. Afshartous

Programming in C UVic SEng 265

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #09. Topic: Structures in C Date:

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

BSM540 Basics of C Language

ET156 Introduction to C Programming

EE C Program Elements

Technical Questions. Q 1) What are the key features in C programming language?

Overview (1A) Young Won Lim 9/14/17

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows

(3-1) Functions II H&K Chapter 3. Instructor - Andrew S. O Fallon CptS 121 (September 5, 2018) Washington State University

Francesco Nidito. Programmazione Avanzata AA 2007/08

Overview (1A) Young Won Lim 9/9/17

Language comparison. C has pointers. Java has references. C++ has pointers and references

WARM UP LESSONS BARE BASICS

Overview (1A) Young Won Lim 9/25/17

Lecture 3. Variables. Variables

Introduction to C. Systems Programming Concepts

Programming. Structures, enums and unions

Functions. Chapter 5

BLM2031 Structured Programming. Zeyneb KURT

C Programming Review CSC 4320/6320

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

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

Dynamic memory allocation

Differentiate Between Keywords and Identifiers

Processes. Johan Montelius KTH

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

Examples for Programming Language Features

CSE 142 Wi01 Midterm 2 page 1 of 6

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

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

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

Exercise: Inventing Language

A process. the stack

Programming Languages

AN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University

Transcription:

Types C Types Void Integral Floating Point Derived Boolean Character Integer Real Imaginary Complex no fractional part fractional part 2 tj

Types C Types Derived Function Array Pointer Structure Union Enumerated 3 tj

Program Structure Structure Chart Calling Module Called Module Main Module Module 1 Module 2 Module 3 Module 1a Module 1b Module 1c Module 2a Module 3a Module 3b Allows solutions to be broken into manageable, understandable and logical pieces 4 tj

Program Structure Structure Chart All communication must go through the Calling/Called Module path Main Module Module 1 Module 2 Module 3 Module 1a Module 1b Module 1c Module 2a Module 3a Module 3b 5 tj

Program Structure Structure Chart All communication must go through the Calling/Called Module path Calling function has control Calling function calls a function The called function receives control When done the called function returns control to the calling function 6 tj

C Program Structure A C program is composed of a series of functions Main is the top level function in C One and only one main function Main may or may not call other functions Energia hides the main function from us The Main function in Energia calls setup() loop() 7 tj

Function Purpose simplified view Receive zero or more pieces of data (parameters) Operate on the data Potentially have a side effect Return one piece of data (return value) Allow one piece of code to be reused with different inputs Allows function libraries to reuse common code # include <stdio.h> 8 tj

User Defined Functions Declaration Definition Call // Function Declarations (prototypes) void greeting(void); int main(void){ greeting(void); return 0; // function call // Function Definition void greeting(void){ printf( Hello EE1910 ); return; 9 tj

User Defined Functions // Function Declarations (prototypes) void greeting(void); int main(void){ greeting(void); return 0; declaration must come before the first use of the function If no data is passed to the function we can use (void) or () // Function Definition void greeting(void){ printf( Hello EE1910 ); return; This function only has a side effect Even if nothing is being returned we should include a return 10 tj

User Defined Functions Function declaration structure return-type function-name(formal parameter list); Formal parameter list structure param-type param-name, param-type param-name, int myfunction(int x, float y, char z); Types must match function definition Strongly encourage names match also 11 tj

User Defined Functions Function definition structure return-type function-name(formal parameter list){ statements; return return_value; int myfunction(int x, float y, char z){ int val; val = x * y - z; return val; 12 tj

User Defined Functions Function call structure function-name(actual parameter list); or var = function-name(actual parameter list); or if (function-name(actual parameter list) == 0){ myfunction(a,b,c); foo = myfunction(a,b,c); if(myfunction(a,b,c) == 12){ The types for a,b,c and foo must match the function definition 13 tj

User Defined Functions int vol(float length, float width, float height); int main(void){ float volume; // enter W, L, H volume = vol(l, W, H); return 0; Actual Parameters Formal Parameters int vol(float length, float width, float height){ return (length * width * height); 14 tj

Functions and Memory Function call transfers execution to a separate section of code (function) When done, the function returns to the next line of code Multiple calls to the same function transfer execution to the same location One copy of the function Must be able to separate date from different calls Executing instructions in line Program Memory Exception Vectors Function Call Text Executable Code Function Code Return Read Only - Data Copy of RAM Data section Boot Loader 15 tj

Functions and Memory Function call creates a space in the heap copy of the actual parameters any function variables (local variables) Function operates in this newly created space (scope) When the function returns, the space is reclaimed (not necessarily erased but no longer available) Data Memory Stack Function memory Copy of parameters Local variables Heap Bss Data 16 tj

Functions and Memory void update_acct(float balance, float int_rate); int main(void){ float balance; float int_rate; printf( balance is: %f, balance); update_acct(balance, int_rate); printf( balance is: %f, balance); return 0; with the original balance of 10,000 and a 10% interest rate what does this print void update_acct(float balance, float int_rate){ balance = balance + balance * int_rate; printf( balance is: %f, balance); return; 17 tj

Functions and Memory int main(void){ float balance; float int_rate; printf( balance is: %.2f\n, balance); update_acct(balance, int_rate); printf( balance is: %.2f\n, balance); return 0; void update_acct(float balance, float int_rate){ balance = balance + balance * int_rate; printf( balance is: %.2f\n, balance); return; balance is 10000.00 balance is 11000.00 balance is 10000.00 Changes in the function are made to the local copies of the variables not to the copy in main The local copies are reclaimed when the function returns 18 tj

Examples 19 tj