* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Chapter 1
Functional programming wikipedia , lookup
Abstraction (computer science) wikipedia , lookup
Falcon (programming language) wikipedia , lookup
Reactive programming wikipedia , lookup
Object-oriented programming wikipedia , lookup
Library (computing) wikipedia , lookup
History of compiler construction wikipedia , lookup
Interpreter (computing) wikipedia , lookup
Programming language wikipedia , lookup
Structured programming wikipedia , lookup
Go (programming language) wikipedia , lookup
Chapter 1 Introduction to C Programming 1.1 INTRODUCTION • This book is about problem solving with the use of computers and the C programming language. • how to identify problems • Specify such problems • Analyze them • Design a method of solution for them 1.2 COMPUTER FUNDAMENTALS • A special-purpose computer is a computer that is designed for a particular function. • General-purpose computers. • They are capable of storing and running different set of instructions, accepting input data for each set of instruction in different forms, and producing output that satisfies various user requirements. Hardware • Main memory, central processing unit, input devices, output devices, and secondary memory devices. • Systems software • Operating system : manages the overall operation of the computer system • Text editor : to create a text • Preprocessor : checks the C program file for special instructions. • Language translator : converts a computer program written using a high-level programming language, to an equivalent program that is in machine language. • Source program : a program that is written in a high-level language • Object program : a program that consists of machine language • Interpreter : translates one instruction at a time and immediately executes • Compiler : translates the entire source program • Standard library contains object codes of some standard programs ( called standard library functions) • Linker : combines the object codes of the needed standard functions with your object program and creates an executable machine language program, called the load module. The load module is saved in disk storage. • Loader : loads the executable load module into the main memory for execution. • Applications software : includes programs that are developed using systems software in order to solve problems. 1.3 PROGRAMMING LANGUAGES • Special-purpose programming language is designed for a particular class of applications. For example, Structured Query Language (SQL) • General-purpose programming language can be used to obtain solutions for many different types of problems. • • Machine Languages Readily understood by the computer. Have some shortcomings: 1. Difficult to learn, instruction is a binary string of zeros and ones. 2. Even relatively simple problems require a large number of machine language instructions. 3. Are machine-dependent. • Assembly Languages • Consist of English-like abbreviations. L 1, GROSSPAY S 1, TAX ST 1, NETPAY • Assemblers, to convert assembly language programs to machine code, have some shortcomings : 1. Programs written in assembly languages are lengthy. 2. Each computer type has its own assembly language. • High-level Languages • English-like, single instruction can be written to corresponds to many operations at the machine level. For example, netpay = grosspay – tax; High-level programming languages have been standardized. Quite portable. • The Evolution of the C and C++ Programming Languages • Developed at Bell Laboratories in the early 1970s as a system implementation language. C combines the convenience of high-level programming languages with the power of assembly languages. • C++ programming language as an extension of the C language. • C++ makes object-oriented programming. 1.4 THE C PROGRAMMING ENVIRONMENT • • Language includes features that enable use to carry out certain basic operations. A library is a collection of routines not part of the language. Two kinds of libraries: 1. Standard libraries 2. Programmer-defined libraries • Stdio library, used for interactive input and output operations; the math library, which contains some standard mathematical functions To use a standard library, say, the stdio library #include <stdio.h> 1.5 HOW TO USE THE COMPUTER TO RUN C PROGRAMS • Accessing the Computer • Using the Editor to prepare Program and Data Files • Compiling, Linking, and Executing C Programs • Correcting Compilations and Execution Errors 1.6 EXAMPLE PROGRAM 1:A C Program that balances Your Checkbook for Debit Type Transactions