Creating a Simple C Program, Compiling, and Executing It
In this initial chapter, the reader will learn how to download, install and use the Code::Blocks Integrated Development Environment. The reader will then write, compile and run his/her first C program. The chapter also covers the basic anatomy of a C prog
- PDF / 831,737 Bytes
- 14 Pages / 504.567 x 720 pts Page_size
- 53 Downloads / 336 Views
Creating a Simple C Program, Compiling, and Executing It
Writing a computer program, in its most basic sense, is the process of putting together a set of instructions in a correct and meaningful sequence for the computer to execute, to achieve some desired result. These instructions tell the computer what to do and how to do it. Instructions that a computer is capable of executing are pre-defined in the computer’s instruction set - only these instructions can be included in a program. Such instructions are (possibly long) strings of 1’s and 0’s, where 1’s represent a certain level of voltage (e.g., 5 volts DC), and 0’s represent a lower level of voltage (possibly 0 volts). These strings of 1’s and 0’s form what is called machine language, and it is the only thing a computer’s processor can understand. (Actually, it is the voltage levels that the processor is able to understand, but that is a topic for a different book.) Certainly a computer program can be written directly in machine language, as they were in the very early days of computing. However, as one can imagine, writing programs composed of very long strings of 0’s and 1’s is an extremely difficult and tedious process, and subject to many errors. To address this problem, computer languages were developed where pseudo-English text statements represent one (or more) machine language instruction(s). A sequence of such text statements comprises the program source code, and is placed in a text file called the source file. (Source files in C typically have a .c extension.) C is one of these so-called high-level programming languages, as are Python, Java, Basic, Pascal, Lisp, Prolog, Fortran and many, many others. From this point forward in our discussion, you should assume that we are referring to C when we mention a high-level programming language, unless otherwise specifically stated. However, as we said above, processors don’t understand text – only 0’s and 1’s. These high-level C language statements in the source code must be translated from text into machine language in order for the processor to understand them. This translation process is called compilation. So, the source file is sent to a C compiler that will “translate” the C language text statements in the source code into machine language instructions that the processor can understand. Then, if successfully compiled (i.e., no errors) and linked to other program files specified in the program (e.g., standard libraries), the program becomes executable – that is, able to execute. The executable file (usually with the file extension .exe) will run, and if correct, it will provide the results sought by the programmer. The difficulty in programming a computer comes from ensuring that appropriate program statements are used, that they are written correctly, set in the correct sequence, and presented with the proper data. This can be bewildering and frustrating to beginner programmers, but rest assured that as one gains experience, it becomes much easier ... and much more fun.
© Springer Nature Switzerlan
Data Loading...