COSC 181 Foundations of Computer Programming Class 2 Goals for Today Finish Up Chapter 1 Introduction Start Chapter 2 Intro to C Programming Go Ahead and Login If you can t sit next to someone who can Typical C Development 1 2 Edit actually write the code labor intensive Preprocess handle compiler directives automatic 3 4 5 6 text replacement outside compilations if any Compile create object code and store on disk Link connect with necessary external resources libraries etc store executable machine code Load put program in main memory really a function of the operating system Execute central processing unit processor performs each individual machine instruction and updates stores data when where indicated Failing To Run Computers are superbly literal and always do only what they are instructed to and no more If instructions cannot be completed as given then the program will fail to run cause an error Run time vs Compile time errors Good Programming Practices 1 Keep it Simple 2 3 4 5 Read the Documentation Make use of the resources available to you DON T get frustrated DON T be scared to experiment 6 find the most straightforward solution build your knowledge base as you go DON T be forced to hurry Introduction to C Fig 2 1 fig02 01 cpp These are comments denoted by Text printing program include iostream allows program to output data to the screen function main begins program execution int main std cout Welcome to C n display message return 0 indicate that program ended successfully end function main Important Components include foo tells the preprocessor to treat the contents of a specified file foo as if those contents had appeared in the source program int main 1 or more functions for each program exactly one function must be called main beginning of every C program in this case returns an integer value return 0 Each function does some processing and returns a value this value may be empty In main this is the very last statement of a C program In general it s the very last statement of any function that its in Could also have said return 1 for instance white space used for making code easier to read Note each statement command is ended by a each function is opened by and closed by certain terms are keywords include int main return Have a pre determined meaning Output std cout Welcome to C n the line as a whole is a statement std cout Standard character output stream Output in C occurs over streams The standard stream above is connected to the monitor by default namespace command std is the namespace defined by iostream cover namespaces later Output Continued stream insertion operator Value on right of is inserted into the stream which appears on the left of Welcome to C n Value on the right of the operator denote a literal string n is a special command called an escape sequence that represents new line in C the backslash lets the compiler know that you want to escape a character and denote an escape sequence See Fig 2 2 in your book for list of escape sequences Now Try It Open up DevC File New Source File Type in the Code Under the Execute menu First hit Compile Save the code on your Desktop Wait for the screen to say Done 0 errors 0 warnings Then under Execute menu hit Run Congratulations on your first C program Now try and make it say something else
View Full Document