C Language: Introduction C Programming CISY 238 Bill Klinger C Language: Introduction
C Language: Introduction RVCC Tutoring Center Room S-020-C C Language: Introduction
C Language: Introduction Outline Computer languages C Background Programming UNIX environment Editor C fundamentals Getting started C Language: Introduction
C Language: Introduction Computer Languages Computers powerful complex use simple instructions Language development machine language assembler high level languages 4GLs C Language: Introduction
Evolution of Computer Complexity C Language: Introduction
C Language: Introduction Early Languages Fortran Formula translation Scientific applications COBOL Common Business Oriented Language Business / data applications C Language: Introduction
C Language: Introduction Language Explosion Algol Designed with programming concepts in mind Basic The first interactive language Simula Extended Algol to facilitate simulations, first O-O language Snobol Specially designed to handle string manipulation LISP Used in artificial intelligence applications PL/1 Language for everyone (therefore no one) C Language: Introduction
C Language: Introduction Created by Dennis Ritchie early 1970’s Bell Labs C comes after B C++ comes after C Design principles high level language allow for detailed control of the system C Language: Introduction
C Language: Introduction UNIX implemented in C Distributed to universities Becomes commercial success widely available efficient C/C++ still the language of choice for ‘serious’ applications C Language: Introduction
C Language: Introduction C Language Usage systems programmers (drivers) operating systems (Linux, UNIX, Windows, et.al.) embedded systems real-time systems games applications education C Language: Introduction
C Language: Introduction ANSI C Standard established to ensure common language set by vendors allows programs to ‘port’ to different computers ANSI American National Standards Institute has established standards for many languages C Language: Introduction
C Language: Introduction A Word About C++ Extends C all of C in C++ C++ adds object oriented programming incorporates classes from Simula does some ‘clean up’ C Language: Introduction
C Language: Introduction Programming The process of translating needs (requirements) into directions a computer can execute. C Language: Introduction
C Language: Introduction Programming An art there is a beauty in good programs it is a creative process A science there is certainty in programs programming requires precision computer will do what it is instructed to lather – rinse – repeat C Language: Introduction
C Language: Introduction The Process Write the code called ‘source code’ written using an editor Compile the code using a compiler creates object modules Link the objects put together the pieces creates the executable Test / debug C Language: Introduction
C Language: Introduction The Process Write the code use vi, pico, notepad, TextPad, or some editor Compile use cc on UNIX Link cc will also link Test / debug C Language: Introduction
C Language: Introduction UNIX Editors vi available on all UNIX / Linux systems primitive but powerful pico simpler than vi less powerful C Language: Introduction
C Language: Introduction The C Language small, efficient and powerful easy to learn (sort of) precise computer control no hidden mechanisms or magic C Standard Library C Language: Introduction
C Language: Introduction C Source File Creation Use text editor (vi, emacs, pico, TextPad, NotePad, etc.) to create a file for C language, the file must have a .c suffix C Language: Introduction
C Executable Program Creation C is a compiled rather than an interpreted language, the .c source file can not be directly executed like a shell script compile using the C compiler cc: $ cc program.c ---> a.out (where a.out is the default executable file name) run program by entering its name: $ a.out can choose a different name for the executable: $ cc -o myprogram program.c ---> myprogram - or: $ mv a.out myprogram C Language: Introduction
C Language: Introduction C Source File // a basic program #include <stdio.h> main() { printf(“Hello World”); } hello.c C Language: Introduction
C Language: Introduction C Source File Contents main function; main tells where the program starts, one and only one main a left brace { is the beginning and a right brace } is the end of a function or code block parentheses ( ) indicate a function definition C Language: Introduction
C Language: Introduction Printing Use the ‘printf’ statement Form printf(“<string>”); Note: string is enclosed in quotes C statement ends in semicolon C Language: Introduction
C Language: Introduction Printing printf ‘prints’ a stream of characters whatever is in <string> is output no automatic “new lines” Use \n to print a new line character printf does not actually print to a printer goes to UNIX standard output default is to terminal C Language: Introduction
C Language: Introduction Variable Basics Must declare variables before using them e.g. int age; int sum, average; Use meaningful names ! C Language: Introduction
C Language: Introduction Statement Basics Assignment indicated with ‘=‘ e.g. sum = 5 + 4; sum = myage + your age; age = age + 1; Note: each statement ends in a semicolon‘;’ = does not mean arithmetic equality C Language: Introduction
C Language: Introduction C Source File // a simple program that prints // the number of fruit #include <stdio.h> main() { int oranges; int apples; int fruit; oranges = 5; apples = 17; fruit = oranges + apples; printf(“We have %d pieces of fruit”, fruit); } fruit.c C Language: Introduction
C Language: Introduction Let’s Get Started Do Hello World program together Exercises listed on web C Language: Introduction