Does someone use compiled BASIC anymore

day 1

week 1

Welcome to "C Programming for Linux in 21 Days." Today's lesson is the starting point for all future experts in this field. Today you will learn:

  • why C is the first choice for programming on Linux
  • what software tools are available to develop C programs under Linux
  • how to find these software tools
  • what the individual steps in the development cycle of a program look like
  • how to write, compile and run your first C program
  • which errors are generated by the compiler and linker

Why C?

Today, in the world of computer programming, there is a large number of high-level programming languages ​​to choose from, for example C, C ++, Perl, Python, Tcl / Tk, BASIC and Java. All undoubtedly excellent programming languages ​​that can easily cope with most programming tasks. Even so, there are a few reasons why professional programmers prefer C:

  • C is a powerful and flexible programming language. Your area of ​​application is only limited by your imagination. The language itself does not impose any restrictions on you. The projects that are implemented with C are very diverse and range from operating systems, word processing systems, graphics, spreadsheets to compilers for other languages. In fact, most C compilers, including GCC, are written in C.
  • C is a popular programming language preferred by professional programmers. As a result, there is a wide range of compilers and useful utilities available for this purpose.
  • C is portable. Portable means that a C program written for a particular computer system (for example an IBM PC with Linux) compiles and runs on another system (perhaps a DEC VAX system) with little or no changes can be executed. This is especially true if you are within the Unix family of operating systems. In addition, a program written for the Microsoft Windows operating system console (also known as an MS-DOS prompt) can be ported to a computer running Linux with little or no modification. This portability is enforced by the ANSI standard for C - the rule set for C compilers.
  • C is a few words programming language because it only uses a handful of terms called keywords. These form the basis for the functionality of C. You may succumb to the belief that a language with more keywords (sometimes called reserved words) would be more powerful. But this is not the case. In the course of your programming work with C, you will find that you can solve almost any programming task with it.
  • C is modular. C code can (and should) be written in routines called functions. These functions can then be reused in other applications or programs. By passing information to the functions, you can generate useful and reusable code.
  • The heart of Linux (also called the kernel) is written in C. So, if you are ever in the embarrassment of writing (or even debugging) a device driver or other code for the Linux kernel, knowledge of C is essential.

As these points show, C is an excellent choice for the novice programmer. But what about C ++? Perhaps you have already heard of C ++ and the associated programming technique of object-oriented programming. You may be wondering what the differences are between C and C ++, and whether you shouldn't be learning C ++ instead of C.

Fortunately, there is no need to worry about that. C ++ is a superset of C, by which I mean that C ++ contains everything from C plus some additions for object-oriented programming. For someone who wants to learn programming first, it is certainly beneficial to learn a small, relatively simple language like C instead of a large, complex language like C ++. If you then devote yourself to the study of C ++, almost everything you have learned about C can be carried over to the superset C ++. Those who learn C not only learn one of the most powerful and popular programming languages, but also prepare for object-oriented programming.

Another programming language that is becoming more and more important is Java. Java is based on C ++, which in turn is based on C. If you later decide to learn Java, you will find that almost everything you learned about C also applies to Java.

Brief historical outline of the C programming language

The C programming language was developed in 1972 by Dennis Ritchie at Bell Telephone Laboratories. The aim of this language was to make programming the Unix operating system easier and to get away from the assembly language. It also made it much easier to exchange programs between computers with different hardware.

C quickly made its performance and flexibility known outside of the Bell laboratories. Programmers everywhere began to set up all sorts of programs. However, different organizations soon developed their own versions of C, and the subtle differences between the implementations were not infrequently a major concern for programmers. To solve this problem, the American National Standards Institute (ANSI) set up a committee in 1983 to develop a standard definition of C, which then became known as the ANSI-C standard. A little later, in the early 1990s, the International Standards Organization (ISO) issued a new standard that was also recognized internationally. With a few exceptions, every modern C compiler complies with these standards.

The programming language C is called C because its predecessor was called B. The B programming language was developed by Ken Thompson, also at Bell Laboratories. You shouldn't have a hard time guessing why it's called B.

First steps before programming

Programs solve problems. They can't solve all problems, but they can solve computer-related problems. If you want to surf the World Wide Web, there is a program called a web browser that will solve this problem for you. This is a specific problem with a specific solution - a web browser. For other computer-related problems there may be no or less than optimal solutions. Let's stay with the example of the web browser. Perhaps you have come up with a suggestion for improving the web browser that you would like to see implemented. That would solve a programming problem.

To solve the programming problem, you should take it step by step. First you need to define the problem. If you don't know the problem, you can't find a solution to it either! Only when you have outlined the problem can you consider how to fix it. Once you have a plan, you can usually implement it as well. Once the plan is in place, you need to review the results to see if they solved the problem. This logic can be applied to many areas, including programming.

If you're writing a program in C (or any other programming language) your steps should look something like this:

  1. Determine the goal of the program.
  2. Find out which tools you want to use to create the program.
  3. Write the program to solve the problem.
  4. Run the program to test the results.

An example of a possible goal (see step 1) would be to develop a word processing system or a database program. A much simpler objective is to put your name on the screen. If you didn't have a goal, you wouldn't be writing a program, so the first step has already been taken.

As a second step, you should determine the tools that you will need to create the program. Do you need a computer program to solve the problem? What information must be taken into account? Which formulas should be used? During this step you should try to determine what knowledge you need and in which order the solution should be implemented.

Let's look at an example. Suppose someone asks you to write a program that finds the area of ​​a circle. Step 1 is done now that you have the goal in mind: calculate the area of ​​a circle. Step 2 is to determine what you need to know to determine the area. In this example, let's assume that the user of this program tells you the radius of the circle. Knowing this, you can apply the formula to get the answer. This gives you everything you need to proceed with steps 3 and 4, also known as the program development cycle.

The cycle of program development

The cycle of program development is in turn divided into different steps. The first step is to use a text editor to create a file that contains the source code. The second step is to compile this source code to create an executable file. The third step is to run the program to see if it works as planned.

The development cycle in C

Step 1 Set up your source code with the help of a text editor. As a rule, source code files in C have the extension (for example meinprog.c, datenbank.c).

Step 2 Compile the program with a compiler. If the compiler does not find any errors, it links the file and creates an executable file. Then go to step 3. If your program contains errors, you must go back to step 1 and correct them first.

Step 3 run the program. You should run tests to make sure that the program works as expected. If not, start over from step 1 and make the appropriate changes or enhancements to your source code.

Figure 1.1 illustrates the steps involved in program development. Typically, unless you have an extremely simple program, you'll go through these steps several times before exiting your program; because even experienced programmers cannot simply sit down and write a complete and absolutely error-free program in just one pass. Since this development cycle (edit-compile-link-test) is run through several times, it is important to familiarize yourself with the necessary tools - the text editor and the gcc compiler.

Figure 1.1: The steps of C program development.

The development tools

To write C programs under Linux, you need additional programs that are probably already installed on your computer. This includes a text editor, a C compiler and tools such as the program and debugger. We investigate what exactly is available when we use the respective tools.

On many other systems such as Apple Macintosh and Microsoft Windows, so-called integrated development environments (abbreviated IDE, for Integrated Development Environment) are now used, which combine text editor, compiler and other tools. Such integrated development environments have also existed for Linux since 1999, but the vast majority of Linux programmers continue to use separate tools.

Generate source code

The source code is a series of instructions or commands that cause the computer to do the tasks you want. As mentioned earlier, the first step in the program development cycle is to enter the source code into a text editor. For example, take the following line of C code:

printf ("Hello, Mom!");

This instruction tells the computer to display the message "Hello, Mom!" On the screen. (We shouldn't be interested in exactly how this instruction works at the moment.)

The text editor

A simple text editor is always preferable to larger word processing systems for creating the source text files. Most word processing systems use special formatting code that is stored in the document. This additional code makes word processing systems unsuitable for creating program source code. The American Standard Code for Information Interchange (ASCII) code defines a standard text format that is understood by almost every program, including the C compiler.

When you save a source text file, you have to give it a name. The name should refer to what the program does. In addition, the source text files of your C program should receive the extension. You can give your source code files any name and extension, but this is the recognized correct extension.

There are many text editors available for Linux, including vi, emacs, joe, ed, vim, crisp, and jed. Some of these editors can be run from the console (the black and white screen you see when Linux starts and before the graphical user interface appears), while others require the X Window graphical user interface. The most recommended editors with an exclusively graphical user interface include nedit, gnp and kedit. The use of these text editors should not be too difficult for anyone who has already worked with a word processing system. In Figure 1.2 these three editors are shown together on one screen.

You can find out whether one of these editors is available on your computer as follows: Enter the respective name followed by the ampersand character (&) in the command line. The & can be obtained by pressing the Shift key together with the 6 key. That way, the editor runs in the background and you can still type commands on the console.

Figure 1.2: Text editor kedit.

Alternative text editors for Linux are best found on one of the many websites on the Internet listing Linux programs for download, or by using an Internet search engine. The best way to do this, however, is to go straight to the web site for the version of Linux you are using.

Compile source code

Even though you may be able to understand C code (you will be able to do so after studying this book at the latest), your computer does not understand the code. A computer needs digital or binary instructions in what is known as machine language. Before your C program can be executed on a computer, the source code must be translated into the machine language. This translation, the second step in program development, is done by a so-called compiler program. The compiler receives your source text as input and uses it to create a file containing the instructions for the source code in machine language.

The best-known C compiler under Linux is the GNU C compiler called gcc.

To see if the C compiler is already installed, enter the command on the command line. Once installed, you will receive a message similar to the message on the console in Figure 1.3. And don't worry if your message is not the same as the one in the picture. Then you probably have a slightly different version of the C compiler. However, if the message says the command could not be found, then you should consult the manual that came with your version of Linux and find out how to install the C compiler. It is advisable to install the other development tools when installing the C compiler.

Figure 1.3: A typical Red Hat 6.1 installation with a console showing the results of the gcc -v and make -v commands.

The compiler is run from the command line. Assuming the source text file radius.c is in the current directory, the command to compile and create an executable file is:

gcc radius.c

This creates an output file in the current directory, which is called traditional. To specify a file name for the output file yourself, you have to call it up as follows:

gcc radius.c -o radius

This command instructs to compile a source file named and produce an output file named. This output file (which could have a completely different name) is an executable file, that is, a program that can be run on your computer. To run the program, enter the command at the command line prompt. The period and the slash signal the command interpreter on the console to look for the program named in the current directory. Without it, the command interpreter would look for it in what is known as the current path (execute the command to view the current path).

However, in addition to compiling your C source code into an executable file, the C compiler can also tell you where compilation errors occurred. However, it would make little sense if the compiler only registered the errors in the source code without showing you where and why the errors occurred. The C compiler can also issue warnings if it encounters code that it can compile but which is likely to lead to an error in the program. Understandably, as a programmer, you want as much information as possible about potential bugs in your program. Therefore it makes sense to set the compiler so that it generates as many warnings as possible. If you also want to control your program with the debugger, you must instruct the compiler to include additional information required by the debugger in the executable file. The call to, which turns on all warnings and adds debug information, is:

gcc -Wall -ggdb radius.c -o radius

The directive tells to issue all possible warnings while serving to add the debug information for the debugger being used by. This is how you will compile most of the programs in this book. On Day 20, "Advanced Compilers," we'll turn to the topic of how to write and compile programs that consist of multiple C code files. But first of all, our programs are all housed in a single source code file.

Complete the development cycle

After your program is compiled and an executable file has been produced, you can run it by typing its name on the console. Remember, however, to put the name in front of it. If after running the program you get results that are not what you expected, you need to go back to step 1. Determine where the problem is, and then modify the code accordingly. Any changes to the source code require the program to be recompiled in order to obtain a corrected version of the executable file. This cycle continues until your program does exactly what it was written for.

Even if you are new to program development, you will soon find that programs rarely do what they are supposed to when they first run. There is a special, frequently used programming tool, the so-called debugger, for locating and correcting errors in a program. A debugger is a program that allows the programmer to go through his program line by line in search of potential errors. Figure 1.4 shows you the debugger, which has a graphical user interface. I encourage you to use this program throughout the book. Use it not only for debugging, but also for learning. Use it to step through your programs and get insight into how your programs work. A little further on, in the section "The ddd Debugger," I'll briefly describe how you can use it to step through a simple program line by line.

Figure 1.4: The ddd debugger. It has two windows: a main window that displays the code and a second, smaller window with control buttons (on the right).

Other programming tools

There is another important programming tool that should be there: the program. After typing in on the command line, you should see a message like Figure 1.3, although it doesn't have to be absolutely identical. We won't deal with the program until day 20, when we come to the compilation of multi-file programs.

The last program you still need is used to view the programmer documentation for your Linux system. In addition to the usual man pages (see Section 1.4), there is a wealth of useful information available in the GNU format. You can display this information with the help of the program. Enter in the console window and you will get an introductory screen to the information system (press for »quit« when you want to quit the program). Unfortunately, the program is not very user-friendly, but many Linux systems have their own documentation reading programs such as or. To find out if one of these programs is installed on your system, all you have to do is type its name on the command line on your console. If one of the programs is available, try to find the information pages "System GNU Info Contents" under and "Info Pages" under. For your information: Both systems can also be used to view the man pages.

Getting started with Linux

In this book, let's just assume that Linux is already running on your system and that you have already checked that the necessary tools are available. Let's also assume that you have the X Window graphical user interface. If this interface is still missing, install it using the documentation for your Linux version.

As soon as you are ready to log into your system, you should bring up a console window (see Figure 1.3). Under the standard installation of Red Hat Linux 6.0 / 6.1 the window is called “Terminal”, under other Linux distributions the console window is called xterm, kconsole or console.

If you are currently registered as a user, i.e. as a system administrator, on your Linux system, you should set up a user account without privileges and use this for your studies of C. The user's account has unrestricted access to the machine and can therefore cause unlimited damage if a program gets out of hand. As a user without privileges on a correctly set up Linux computer, you could in the worst case damage your own files. You are extremely unlikely to damage files that are part of or required by the operating system.

When the console window appears, try a number of the most common commands, such as (List Directory), (Output Working Directory), (List Processes), (Create Directory), and (Change Directory). All Linux commands are case-sensitive. The order (if it existed) does not correspond to the order. For more information on these programs, see the man pages (using the command). Calling, for example, will give you everything you need to know about the command. To exit the man page, press the key to return to the command line. Most versions of Linux contain man pages for almost all programs and operating system features.

The console actually consists of two programs: one for the window itself and a second, the so-called command interpreter, which, as the name suggests, interprets and executes the commands entered by the user. The most widely used command interpreter on Linux is called GNU (Bourne Again SHell), although many others are available as well.

Most of the programs in this book that you will write to practice C programming are executed from the command line of a console.

Your first C program

You are probably eagerly waiting to write your first program in C. So that you can quickly get to grips with your compiler, you will find a short program in Listing 1.1 with which we will practice the cycle of program creation. You may not understand everything at the moment, but you will at least get a feel for the flow of the development cycle: writing, compiling, and running a proper C program.

This example is a program called that does nothing but print the words "Hello, world!" This program, which is traditionally used to introduce C programming, is a good learning example. The source code for is in Listing 1.1. If you type in this listing, you will need to omit the line numbering and colons to the left.

Listing 1.1: hello.c.

1: #include
3: int main (void)
4: {
5: printf ("Hello, World! \ N \ n");
6: return 0;
7: }

Make sure that it is installed on your computer as described above and that it is working properly and that you have a suitable text editor. When the compiler and editor are ready, follow the steps below to enter, compile, and run.

Enter hallo.c and compile

When entering and compiling the program, do the following:

  1. In the console window, use the cd command to change to the directory in which you want to save the C program and start your text editor. For example, if you are using nedit as your editor, enter the command nedit & at the command prompt.
  2. Using the keyboard, enter the source code of exactly as in Listing 1.1. Press Enter after each line.

Leave out the line numbers and colons. They are only used to make it easier to refer to specific lines of code in this book.

  1. Save the source code. Name the file.
  2. Verify that is on your hard drive by viewing the list of files in the directory with the command in the console window. Among the files displayed should also be found.
  3. Compile to a proper program using the following command in the console window. gcc -wall -ggdb hello.c -o hello
  4. Check the compiler messages. If you don't get any errors or warnings, everything should be fine.
  5. If you make a mistake while typing the program, the compiler will catch the error and display an error message. For example, if you had entered the word instead, you would get something like the following message: hello.c: In function `main ':
    hallo.c: 5: warning: implicit declaration of function `prntf '
    /tmp/cco48R7q.o: In function `main ':
    /home/erikd/hello/hallo.c:5: undefined reference to `prntf '
    collect2: ld returned 1 exit status
  6. If you get this or a similar error message, you should return to step 2. Open the file in your editor. Again, carefully compare the contents of your file with Listing 1.1. Make any necessary corrections, then go to step 3.
  7. Your first C program should now be compiled and executable. If you now list all files with the name (and any extension) from the directory, you should get the following result:
  8. - the source text file that you created with your editor
  9. -as executable program generated when compiling and linking
  10. To run, all you have to do is type. This puts the message "Hello, World!" On the screen.

My congratulations! You have just entered, compiled and executed your first C program. Granted, it's a simple program that doesn't actually do anything particularly useful, but it's a start after all. And to be honest, most of today's C experts learned C the exact same way - by compiling. So you are in good company.

Compilation error

A compilation error occurs when the compiler finds something in the source code that it cannot compile. Misspelling, typographical errors, or a dozen other things can cause the compiler to fail. Fortunately, however, modern compilers don't abort the compilation process without telling you why they failed and what the problem is. This makes it much easier for you to track down and correct errors in your source code.

To illustrate this to you, an error was deliberately inserted into the program from above. If you've worked through the example (and you should), you will have a copy of it on your hard drive by now. Call up your editor and place the cursor at the end of the line with the call to. Remove the final semicolon there. Then it should look like Listing 1.2.

Listing 1.2: hallo.c with an error.

1: #include
3: int main (void)
4: {
5: printf ("Hello, world! \ N \ n")
6: return 0;
7: }

Then save the file. Now you can recompile it. To do this, enter the appropriate command to the compiler. Because of the error, the compilation will not complete. Instead, the compiler shows you something like the following message:

hallo.c: In function `main ':
hello.c: 6: parse error before `return '
hallo.c: 7: warning: control reaches end of non-void function

The little bug you built in triggered three compiler messages. Each message gives the name of the C source text file at the beginning of the line, the second and third messages even include the number of the line in which the error was detected. Note that the third message is a warning.

The messages are quite informative. They tell you that in the function 'something went wrong and in line 6 before' an error occurred. Why, you might ask, does the compiler detect an error on line 6 when we've removed the semicolon from the end of line 5? The answer is that C doesn't register anything like line breaks. The semicolon behind the statement could just as easily have been placed in the next line (even if this does not necessarily correspond to current programming practice). Only when the compiler encounters the next command () in line 6 does it know that the semicolon is missing. Therefore, for the compiler, the error is on line 6.

You should also keep in mind that an error in one part of the program (line 6) can sometimes cause another error later in the program (line 7). From this you can learn the following: If the compiler lists several errors and you can only find one, you should fix that error first and then recompile the program. Perhaps you have already eliminated all other errors and can compile the program without any further error messages.

With that, one point regarding the C compiler and its error messages should have become absolutely clear. A compiler may be smart enough to pinpoint and pinpoint errors, but it is not an Einstein. With your knowledge of the C programming language, you must interpret the compiler error messages and determine the actual position of the errors noted. Most of the time, the errors are on the line specified by the compiler, and if not, they are almost always on the previous line. You will certainly have a bit of trouble tracking down the errors at the beginning, but that will soon subside.

The ddd debugger

In the C development cycle section, the fourth step was to run the program to see if it ran correctly. It is easily possible to write a C program that can be compiled without any problems, but still does not meet the objectives. In this case we are talking about a logical error compared to the compilation errors we discussed in the previous section. Finding logical errors in large programs is much more difficult than identifying compile errors. The debugger is a valuable help here because it enables us to go through a program line by line. In this way you can follow the program flow line by line and check whether the program works as you intended when you wrote the program. In this book, we will use the debugger less for debugging and more as a learning aid.

Before you can use the debugger, you must first set it up correctly. Assuming you already have it available, then start it from the console window by typing. If this is your first time using it, you'll need to click your way through a startup screen or two until you get to the main window. Then click on Edit in the menu bar and select GDB Settings from the associated menu. You will then be taken to a dialog box with a scroll bar on the right. Use this scroll bar to scroll approximately to the middle until you come to the item Autoloading of Shared Library Symbols. Then, as shown in Figure 1.5, click the check box to the left of that point to remove the check mark so that the option is turned off. To save your changes, click the OK button in the dialog box, and then click Save Options on the Edit menu.

You can now start debugging a program. Set up the source code for the following program in your editor (Listing 1.3) and compile it. Be sure to say to add the debug information that the debugger needs. The executable program should be named.

Listing 1.3: hello2.c, a program for experimenting with the debugger.

1: #include
2 :
3: int main (void)
4: {int count;
5 :
6: printf ("Hello !!! \ n");
7 :
8: printf ("Start ... \ n");
9: for (count = 0; count <5; count ++)
10: printf ("counter =% d \ n", count);
12: printf ("done. \ N \ n");
14: return 0;
15: }

Figure 1.5: Setting up the ddd debugger.

After the program has properly compiled and executed, you are ready to use the debugger. To invoke the debugger for this program, type after the Command prompt of the console window

ddd hello2

a. This should bring up the two debugger windows and a tips on how to work with dialog box (close the dialog box in a moment). The main window should contain the source code.

The first step in working with is to set an initial breakpoint where you want the debugger to stop after initializing. To do this, click in the main window to the far left of the first line that contains a "" statement (line 6), and then click on the "break" button in the toolbar (button with the stop symbol above). A stop sign should appear on the line with the command. Now you can click the Run button on the floating button bar, whereupon a green arrow will appear next to the stop sign. If you now click the Step button in the toolbar, you can go through the code line by line. The output produced by each line of code appears in the lower part of the main window. It stands to reason that the debugger cannot go past the end of the program, but you can always have the debugger go through the program from the beginning by clicking the Run button.

Don't be afraid to use the debugger to go through the sample programs in this book. Working with the debugger will give you a much better insight into the interaction between the C programming language and the way your computer works.


After reading this lesson, you should be confident that you made a wise choice in choosing C as your programming language for Linux. C combines power, popularity and portability in an unmatched way. These factors, together with the close relationship to object-oriented languages ​​such as C ++ or Java, make C almost unbeatable.

In this lesson, you learned about the various steps involved in creating a C program - a process known as program development. You should now be familiar with both the Edit-Compile-Test cycle and the tools required for each step.

Errors are an inevitable part of program development. Your C compiler can track down these errors in your source code and output an appropriate error message that tells you what type of error and where to find it. You can use this information to edit your source code again and correct the error. Remember, however, that the compiler cannot always determine the type and location of the error with 100% certainty. Sometimes you need to use your knowledge of C to find out what exactly caused an error message.

questions and answers

If I used a text editor to enter my source code that I don't really like, can I switch to a different one without re-entering the code that was previously set up? Are all text editors compatible with each other?

Yes, all text editors are compatible. If you are using a text editor rather than a word processor, the files you create will contain only ASCII characters. Switching to another text editor should therefore not be a problem, even if some editors may display the [ÿ] character a little differently and equate it with four spaces instead of the usual eight.

If I want to make a program that I have written available to someone else, which files do I have to give him / her with?

One of the advantages of C is that it is a compiled language. This means that after the source code has been compiled, you will get an executable program. This executable program is independent. So if you want to give it to all of your friends who work on Linux, nothing stands in the way. All you have to do is give you the executable program.

However, if you want to give this person the opportunity to adapt the program to his own needs or his computer, you must provide him with the C source code. However, this source code must first be compiled before it can run on the new computer. If necessary, include instructions on how to compile your program.

Do I need to keep the source code (.c) file after creating an executable file?

If you delete the source text file, you are giving yourself the opportunity to make changes to the program. Therefore, you should keep this file. As long as you have the source code (.c) file, you can always recreate the other files.

Can I ignore the error messages?

Some warnings affect the execution of the program and others do not. If the compiler issues a warning, it should be a signal to you that something is wrong. You should analyze each warning and make a decision. It is best if you write your programs so that they contain absolutely no warnings or errors. (If an error occurs, the compiler will not produce an executable file.)


The workshop contains quiz questions to help you consolidate your knowledge, as well as exercises to encourage you to apply what you have learned and gain your own experience. The solutions to the questions and the exercises can be found in Appendix C.


  1. What are three reasons why C is the best choice as a programming language.
  2. What does the compiler do?
  3. What are the steps in the program development cycle?
  4. What command do you have to enter to use to create a program named from a C source file named?
  5. Which extension should you use for your C source code files?
  6. Is a valid name for a C source file?
  7. What to do if a compiled and executed program does not behave as expected?
  8. What is machine language?
  9. What does the debugger do?
  10. What information is required by the debugger and provided by the compiler?


  1. Use your text editor to look at the executable file you generated from Listing 1.1. Does the executable look like the source code file? (Do not save this file when you exit the editor.)
  2. Enter the following program and compile it. What does the program do? (Leave out the line numbers and the colons at the beginning of the line.) 1: #include
    3: int radius, area;
    5: int main (void)
    6: {
    7: printf ("Enter a radius (e.g. 10):");
    8: scanf ("% d", & radius);
    9: area = (int) (3.14159 * radius * radius);
    10: printf ("\ n \ nArea =% d \ n", area);
    11: return 0;
    12: }
  3. Enter the following program and compile it. What does the program do? 1: #include
    3: int x, y;
    5: int main (void)
    6: {
    7: for (x = 0; x <10; x ++, printf ("\ n"))
    8: for (y = 0; y <10; y ++)
    9: printf ("X");
    11: return 0;
    12: }
  4. TROUBLESHOOTING: The following program has a problem. Enter it into your editor and compile it. Which lines generate error messages? 1: #include
    3: int main (void);
    4: {
    5: printf ("Find next!");
    6: printf ("You will find \ 's! \ N");
    7: return 0;
    8: }
  5. TROUBLESHOOTING: The following program has a problem. Enter it into your editor and compile it. Which lines generate error messages? 1: #include
    3: int main (void)
    4: {
    5: printf ("This is a program with a");
    6: do_es ("Problem!");
    7: return 0;
    8: }
  6. Make the following change to the program in Exercise 3. Compile and run the program again. What is the program doing now? 9: printf ("% c", 1);