1 / 26

C Programming course

C Programming course. Exercise 1. Technical details. Teaching assistant: Olga Sorkine TA Home page: http://www.cs.tau.ac.il/~sorkine /courses/cprog06/ Lectures homepage: http://www.cs.tau.ac.il/~armon/prog06a.htm. Technical details. My e-mail: sorkine@tau.ac.il

lisawheeler
Download Presentation

C Programming course

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C Programming course Exercise 1

  2. Technical details • Teaching assistant: Olga Sorkine • TA Home page: http://www.cs.tau.ac.il/~sorkine/courses/cprog06/ • Lectures homepage: http://www.cs.tau.ac.il/~armon/prog06a.htm

  3. Technical details • My e-mail: sorkine@tau.ac.il • Office hours: Tuesday 11:00 – 12:00 Schreiber building, room 002 (Computer Graphics lab) • Office phone: 03-6405360

  4. Technical details • We will be working with Visual Studio 6.0 programming environment. • You can practice/do your homework in rooms 1, 9, 10 (open 8:00 – 20:00 weekdays and till 12:00 Fridays) • If you prefer to work at home, you can install lcc (I will explain next time).

  5. Recommended books • The C Programming Language (second edition - ANSI C), Brian W. Kernighan and Dennis M. Ritchie, Prentice Hall, Inc., 1988. • A Book on C (third or fourth edition), Al Kelley and Ira Pohl, Addison-Wesley, 1997. • These and other C programming books can be found in the library under 519.83

  6. Homework • Weekly homework assignments • The assignments are individual • Submit a hardcopy • The assignments are worth 20% of the final grade. The rest – a written exam.

  7. Recitations (= ‘tirgul’) • Review and sometimes enhance the material given at the lectures • Practice • Of course, Q&A

  8. What can a computer do? Strictly speaking, very little: • Store and retrieve numbers • very quickly • very accurately • Add, subtract, multiply, and divide • also fast and accurate • Compare numbers (with 0) • Follow a list of instructions • jump around in the list

  9. What about everything else? • More complex math • Combination of atomic operations • Interaction with peripheral devices • Output: graphics cards and printers • Input: keyboards, mice, joysticks • All sorts of specialized devices • Everything done using numbers • To the computer everything is numbers

  10. What numbers does a computer work with? • Instructions. • Addresses. • Data: • Integer numbers • Real numbers • Text • All sorts of other things

  11. Basic computer model

  12. What is a computer program? • A sequence of processor instructions designed to achieve a specific purpose. • The instructions are executed sequentially. • Each instruction has a numerical code.

  13. Examples of instructions • Load data (from an address in the memory) • Store data (in an address) • Add two numbers • If two numbers are equal, jump to another part of the program • Instructions are numbers!

  14. Machine language • Computers understand only machine language. • Every processor has its own machine language. • Basically looks like a sequence of 1’s and 0’s. • Very inconvenient to work with and non intuitive. • All other computer languages were created for human convenience • The computer does not understand C. • Must be converted into machine language.

  15. Computer languages (getting closer to human languages) • Assembly – machine language with some text codes (still inconvenient) • Interpreted languages – Java, Perl, MATLAB • The program is translated into machine language line by line during execution • Compiled languages – C, C++, Pascal, Fortran… • The program is translated into machine language before execution

  16. High level languages vs. machine languages. Actually, binary instructions.

  17. C is a procedural language • It enables the user (= the programmer) to create new instructions (procedures) from existing ones. • Instead of re-writing the same code over and over again, write it once and call it when needed.

  18. Why different languages? • Many languages were developed with specific applications in mind: • Data processing • Web applications • Mathematical calculations • Artificial intelligence

  19. How do we compile? • A special program – the “compiler” – “translates” from computer language to machine language. • There are many compilers on the market. • In class, we will work with Microsoft Visual C++ 6.0 (a.k.a. Visual Studio 6.0)

  20. Let's look at the whole process • Write a program • Your favorite text editor • Compile + link the program • C compiler • will do one of two things: • print error messages and abort (most probably…) • produce an executable program • Run the program

  21. Compilation – more details Machine language with “holes” Compilation Executable Source1.c Source1.obj Linker Machine language with “holes” myprog.exe Compilation Source2.c Source2.obj

  22. Our first C program /* HelloWorld – An example program */ #include <stdio.h> int main( ) { printf(“Hello, world!\n”); return 0; } This is an instruction to the compiler to insert the contents of the file stdio.h to the program prior to compilation. This file contains information about the printf fuction. This is a C statement. This statement calls a function called printf, which causes text to be printed on the screen. Note that all C statements end with a semicolon (;). Yet another C statement. This one terminates the program and informs the operating system that it has ended successfully. This tells the compiler we are about to define a function named main. main is a special function – it is where the program starts running. This is a comment – starts with a /* and ends with a */. Comments are used to explain the program to a human reader, and are ignored by the compiler. Curly braces indicate the beginning and end of a block of instructions. Specifically in this case – a function.

  23. Now, let’s get to work!!! Help using Microsoft Visual C++

  24. In-class assignments • Write, compile and run the “Hello World” program. • Slightly modify your program so that it prints your first name in one line, and your second name the next line.

  25. A name printing program /* This program prints my name on the screen in two lines. */ #include <stdio.h> int main( ) { printf(“Olga\nSorkine\n”); return 0; }

  26. See you next time

More Related