Lecture2

Lecture2 - ECE15: Introduction to Computer Programming...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE15: Introduction to Computer Programming Using the C Language Lecture Unit 2: First Steps in C
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture Unit 2 ECE15: Introduction to Computer Programming Using the C Language 2 Outline of this Lecture A Few Very Useful Things: Comments and Documentation Functions and their Parameters Including Header Files with #include Standard Library Functions printf() and scanf() User interface for the simple adder program Basic building blocks of the C language: Keywords and identifiers Variables and constants Defining symbolic constants with #define Basic data types in C: int, char, double
Background image of page 2
/* The traditional first program in honor of Dennis m Ritchie who invented C at Bell Labs in 1972 */ #include <stdio.h> int main() { printf( "hello world!\n" ); return 0 ; } Lecture Unit 2 ECE15: Introduction to Computer Programming Using the C Language 3 “hello world” Program Revisited Comment Output to screen using a function call Function main() Inclusion of a file Returned value In the following slides, we will review all these components!
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture Unit 2 ECE15: Introduction to Computer Programming Using the C Language 4 Comments and Their Syntax A comment is any text found between /* . .. */ . Specifically, a comment starts with /* and ends with */ . Comments do absolutely nothing, but are very useful for humans. Comments can span several lines (or several pages), but they cannot be nested: Here is another valid way (introduced in C99) to include comments. Any text from // till the end of the same line: /* This is /* a very long and invalid (nested) /* comment. */ /* A second comment.*/ // This is a comment. a = b + c; // This is another comment.
Background image of page 4
Lecture Unit 2 ECE15: Introduction to Computer Programming Using the C Language 5 Functions in C In general, a function is “a convenient way to encapsulate some computation” which can then be invoked via a function call. Every function can do the following: Accept parameters Return a value Functions are called “procedures” or “routines” in other languages. Every function has a declaration and a definition as follows Declaration: describes the function’s name, the type of its parameters, and the type of value it returns. Definition: contains the declaration (again) as well as the code that actually implements the function’s computation. Before a function can be invoked, its declaration must be given. We will talk much more about functions in this course! Function Returned Value Parameters Input & Output
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture Unit 2 ECE15: Introduction to Computer Programming Using the C Language 6 Simple Function: An Example float power( float x, int n) { float p; int i; p = 1.0 ; for (i = 0 ; i < n; i++) p = p*x; return p; } float power( float x, int n); Name Type of re- turned value Types of parameters Declaration: Definition:
Background image of page 6
Lecture Unit 2 ECE15: Introduction to Computer Programming Using the C Language 7 The Function main() Every C program must contain a function called main .
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/07/2009 for the course CHEM 6A taught by Professor Pomeroy during the Spring '08 term at UCSD.

Page1 / 35

Lecture2 - ECE15: Introduction to Computer Programming...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online