Your SlideShare is downloading. ×
0
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Introduction

334

Published on

another intro

another intro

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
334
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. CS 251 C Programming Language Spring 2010 Instructor: Dick Lang TA: Joseph Sturtevant
  • 2. Goals <ul><li>We will learn </li></ul><ul><ul><li>Read: Understand programs written in C language </li></ul></ul><ul><ul><li>Write: Design and implement programs using C language </li></ul></ul><ul><ul><li>Compile: Use compiler to convert C code into executable file in the UNIX environment. </li></ul></ul><ul><ul><li>Execute: Run corresponding code to get results </li></ul></ul><ul><ul><li>Debug: Identify and fix syntax and semantic errors in C code . </li></ul></ul><ul><ul><li>Use of Visual Studio in the Windows environment </li></ul></ul><ul><li>Appropriate for </li></ul><ul><ul><li>Technically oriented people with little or no programming experience, but with a strong mathematics backround </li></ul></ul>
  • 3. View of Computers <ul><li>From a programmer’s viewpoint </li></ul><ul><ul><li>Computers are tools </li></ul></ul><ul><ul><li>A computer program turns raw data into meaningful information </li></ul></ul><ul><ul><li>A program is the driving force behind any job that any computer does </li></ul></ul><ul><ul><ul><li>A program is a list of detailed instructions </li></ul></ul></ul><ul><ul><ul><li>These instructions are written in a particular programming language </li></ul></ul></ul>
  • 4. Your Mindset… <ul><li>From an engineer’s point of view: </li></ul><ul><ul><li>A computer/program may control a mechanism or process </li></ul></ul><ul><ul><li>A computer/program may analyze data and aid in drawing conclusions or decision-making </li></ul></ul><ul><ul><li>A computer can model a mechanism or process in advance of constructing it </li></ul></ul><ul><li>Embedded computers are components of most mechanical systems and products </li></ul>
  • 5. Available Programming Languages <ul><li>Machine Languages </li></ul><ul><li>Assembly Languages </li></ul><ul><li>High-level Languages </li></ul><ul><ul><li>C/C++ </li></ul></ul><ul><ul><li>COBOL (obsolete) </li></ul></ul><ul><ul><li>Pascal (academic) </li></ul></ul><ul><ul><li>Fortran (nearing obsolesense) </li></ul></ul><ul><ul><li>Java </li></ul></ul><ul><ul><li>Python </li></ul></ul><ul><ul><li>Etc… </li></ul></ul>
  • 6. Machine Languages <ul><li>System of instructions and data directly understandable by a computer&apos;s central processing unit. </li></ul><ul><li>Example: </li></ul><ul><ul><ul><ul><ul><li>100011 00011 01000 00000 00001 000100 </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>000010 00000 00000 00000 10000 000001 </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>000000 00001 00010 00110 00000 100000 </li></ul></ul></ul></ul></ul><ul><li>Every CPU model has its own machine code, or instruction set, although there is considerable overlap between some </li></ul>
  • 7. Assembly Languages <ul><li>Human-readable notation for the machine language that a specific computer architecture uses representing elementary computer operations (translated via assemblers) </li></ul><ul><li>Example: </li></ul><ul><ul><ul><ul><ul><li>load hourlyRate, r1 </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>mul workHours, r1 </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>store salary, r1 </li></ul></ul></ul></ul></ul><ul><li>Even into the 1990s, the majority of console video games were written in assembly language. </li></ul>
  • 8. High-level Languages <ul><li>Higher level of abstraction from machine language </li></ul><ul><ul><li>Codes “similar” to everyday English </li></ul></ul><ul><li>Use mathematical expressions (translated via compilers) </li></ul><ul><ul><li>Example: </li></ul></ul><ul><ul><ul><ul><li>salary = hourlyRate * workHours </li></ul></ul></ul></ul><ul><li>Make complex programming simpler =&gt; make programming more productive &amp; reliable </li></ul>
  • 9. Why Program using C <ul><li>Initial development occurred at Bell Labs in early 70’s by Ritchie, as part of Unix OS development </li></ul><ul><li>General-purpose computer programming language </li></ul><ul><ul><li>high-level assembly </li></ul></ul><ul><ul><li>Simplicity and efficiency of the code </li></ul></ul><ul><li>Most widely used programming language </li></ul><ul><ul><li>Commonly used for writing system software </li></ul></ul><ul><ul><li>Widely used for writing applications </li></ul></ul><ul><ul><li>Hardware independent (portable, mostly) </li></ul></ul><ul><ul><li>Great influence on many other popular languages (C++, Java) </li></ul></ul>
  • 10. Textbooks <ul><li>Required </li></ul><ul><ul><li>Programming in C (3rd Edition) by Stephen Kochan. ISBN: 0672326663. Link for the book from amazon: </li></ul></ul><ul><ul><li>http://www.amazon.com/gp/product/0672326663 </li></ul></ul><ul><li>Recommended Reading </li></ul><ul><ul><li>Absolute Beginner&apos;s Guide to C by Greg Perry. ISBN: 0672305100. Link </li></ul></ul><ul><ul><li>http://www.amazon.com/gp/product/0672305100 </li></ul></ul>
  • 11. Outline of the Course – I <ul><li>Introductory information </li></ul><ul><li>C program structure </li></ul><ul><li>Basic data types and variables declaration </li></ul><ul><li>Arithmetic expressions and operators </li></ul><ul><li>Control statements. </li></ul><ul><ul><li>Conditional statements </li></ul></ul><ul><ul><li>The while loop </li></ul></ul><ul><ul><li>The do while loop </li></ul></ul><ul><ul><li>The for loop </li></ul></ul><ul><ul><li>The if else statement </li></ul></ul><ul><ul><li>The switch statement </li></ul></ul><ul><ul><li>The break statement </li></ul></ul><ul><ul><li>The continue statement </li></ul></ul>
  • 12. Outline of the Course – II <ul><li>Formatted Input and Output </li></ul><ul><li>Arrays and Strings </li></ul><ul><li>Functions </li></ul><ul><ul><li>Declarations </li></ul></ul><ul><ul><li>Calling </li></ul></ul><ul><li>Pointers </li></ul><ul><li>Struct(ures) </li></ul><ul><li>Preprocessor </li></ul><ul><li>* Advanced Material </li></ul><ul><ul><li>Debug using gdb and/or Visual Studio </li></ul></ul><ul><ul><li>Binary Trees </li></ul></ul><ul><ul><li>Link Lists </li></ul></ul><ul><ul><li>Recursive Functions </li></ul></ul><ul><li>* may be adjusted according to time and interests of students </li></ul>
  • 13. History- I <ul><li>ENIAC I ( E lectrical N umerical I ntegrator A nd C alculator) </li></ul><ul><li>John Mauchly and J Presper Eckert </li></ul><ul><li>500,000 dollars </li></ul><ul><li>Thousand times faster </li></ul><ul><ul><li>17,468 vacuum tubes </li></ul></ul><ul><ul><li>70,000 resistors </li></ul></ul><ul><ul><li>10,000 capacitors, etc </li></ul></ul><ul><ul><li>800 square feet floor space </li></ul></ul><ul><ul><li>30 tons </li></ul></ul><ul><ul><li>160 kilowatts of electrical power </li></ul></ul>The ENIAC 1946
  • 14. History- II <ul><li>First home computer </li></ul><ul><ul><li>Mark-8 Altair </li></ul></ul><ul><ul><li>IBM 5100 Computers </li></ul></ul><ul><li>1974/1975 </li></ul><ul><li>Altair </li></ul><ul><ul><li>8080 CPU </li></ul></ul><ul><ul><li>256 Byte RAM card </li></ul></ul><ul><ul><li>$400 </li></ul></ul><ul><ul><li>The consumer needs to put them together, make it work and write any needed software. </li></ul></ul><ul><ul><li>Paul Allen and Bill Gates develop BASIC for the Altair 8800 </li></ul></ul>Mark-8 Altair
  • 15. History- V <ul><li>Personal computer </li></ul><ul><ul><li>Apple II in 1977 </li></ul></ul><ul><ul><li>IBM PC in 1981 </li></ul></ul><ul><ul><li>Apple Macintosh in 1984 </li></ul></ul><ul><ul><li>Microsoft Windows 1.0 ships in November, 1985 </li></ul></ul>original IBM PC 1981
  • 16. Operating System <ul><li>What is an OS? </li></ul><ul><ul><li>A program that allows you to interact with the computer -- all of the software and hardware </li></ul></ul><ul><ul><ul><li>With a command-line operating system (e.g., DOS) </li></ul></ul></ul><ul><ul><ul><li>With a graphical user interface (GUI) operating system (e.g., Windows) </li></ul></ul></ul><ul><li>Two major classes of operating systems </li></ul><ul><ul><li>Windows </li></ul></ul><ul><ul><ul><li>Nice interface ?, easy to learn ? </li></ul></ul></ul><ul><ul><li>Unix </li></ul></ul><ul><ul><ul><li>reliable timesharing operating system </li></ul></ul></ul><ul><li>Embedded computers use “real-time” OS’s which do not require disks… </li></ul>
  • 17. Why choose UNIX <ul><li>Powerful </li></ul><ul><ul><li>Multi-user operating system </li></ul></ul><ul><ul><li>Good programming tools </li></ul></ul><ul><ul><ul><li>Most heavy-duty database management systems started out on Unix </li></ul></ul></ul><ul><li>Flexible   </li></ul><ul><ul><li>Thousands of tools that can be combined and recombined. </li></ul></ul><ul><li>Reliable </li></ul><ul><ul><li>Unix is hard to crash. </li></ul></ul><ul><li>Simple things are simple in Unix… We’ll move to Windows later in the semester. </li></ul>
  • 18. Your First Program <ul><li>#include &lt;stdio.h&gt; </li></ul><ul><li>int main() </li></ul><ul><li>{ </li></ul><ul><li>printf(&amp;quot;Hello World &amp;quot;); </li></ul><ul><li>return 0; </li></ul><ul><li>} </li></ul>Preprocessor: interact with input/output of your computer You will see this at the beginning of nearly all programs Tells computer to load file named &lt;stdio.h&gt; &lt;stdio.h&gt; allows standard input/output operations
  • 19. Your First Program <ul><li>#include &lt;stdio.h&gt; </li></ul><ul><li>int main() </li></ul><ul><li>{ </li></ul><ul><li>printf(&amp;quot;Hello World &amp;quot;); </li></ul><ul><li>return 0; </li></ul><ul><li>} </li></ul>Start point of the program Preprocessor: interact with input/output of your computer <ul><ul><li>C programs contain one or more functions, exactly one of which must be main </li></ul></ul><ul><ul><li>int means that the function main will &amp;quot;return&amp;quot; an integer value </li></ul></ul>
  • 20. Your First Program <ul><li>#include &lt;stdio.h&gt; </li></ul><ul><li>int main() </li></ul><ul><li>{ </li></ul><ul><li>printf(&amp;quot;Hello World &amp;quot;); </li></ul><ul><li>return 0; </li></ul><ul><li>} </li></ul>Start point of the program Preprocessor: interact with input/output of your computer Start and finish of function
  • 21. Your First Program <ul><li>#include &lt;stdio.h&gt; </li></ul><ul><li>int main() </li></ul><ul><li>{ </li></ul><ul><li>printf(&amp;quot;Hello World &amp;quot;); </li></ul><ul><li>return 0; </li></ul><ul><li>} </li></ul>Printing a line of Text Start point of the program Preprocessor: interact with input/output of your computer Start and finish of function
  • 22. Your First Program <ul><li>#include &lt;stdio.h&gt; </li></ul><ul><li>int main() </li></ul><ul><li>{ </li></ul><ul><li>printf(&amp;quot;Hello World &amp;quot;); </li></ul><ul><li>return 0; </li></ul><ul><li>} </li></ul>Printing a line of Text Start point of the program Preprocessor: interact with input/output of your computer Start and finish of function New line character
  • 23. Your First Program <ul><li>#include &lt;stdio.h&gt; </li></ul><ul><li>int main() </li></ul><ul><li>{ </li></ul><ul><li>printf(&amp;quot;Hello World &amp;quot;); </li></ul><ul><li>return 0; </li></ul><ul><li>} </li></ul>Printing a line of Text Start point of the program Preprocessor: interact with input/output of your computer Start and finish of function Finish and return value 0 <ul><ul><li>A way to exit a function </li></ul></ul><ul><ul><li>It means that the program terminated normally in this case </li></ul></ul>
  • 24. Comments for programs <ul><li>Why comments are needed </li></ul><ul><ul><li>Good habit </li></ul></ul><ul><ul><li>Readable to others </li></ul></ul><ul><ul><li>Remind yourself </li></ul></ul><ul><li>How to comment </li></ul><ul><ul><li>/* … */ </li></ul></ul><ul><ul><li>// … </li></ul></ul><ul><li>Examples </li></ul>
  • 25. Compiler <ul><li>What is compiler </li></ul><ul><ul><li>A computer program (or set of programs) that translates text written in a computer language ( the source code ) into another computer language (usually, an executable file ) </li></ul></ul><ul><li>Why we need a compiler </li></ul><ul><li>Available C compiler in UNIX system: gcc </li></ul><ul><ul><li>gcc sourcefile.c –o exefile.exe </li></ul></ul>
  • 26. Procedure This is your C program. Type the code in any standard text editor, and save it as helloworld.c Type gcc helloworld.c –o helloworld to compile helloworld.c into helloworld using the gcc compiler The gcc compiler generates the corresponding executable code named helloworld . The computer can execute this machine readable code if you type ./helloworld #include &lt;stdio.h&gt; int main() { printf(&amp;quot;Hello World &amp;quot;); return 0; } helloworld.c C-compiler 0011 0000 1010 0110 1100 0110 1011 0101 1010 1110 0110 1110 helloworld.exe

×