this book.
In the next lesson you’ll learn to write your first C program.
03 067231861x CH01 4.10.2000 10:59 AM Page 25
Taking the First Step
25
Q&A
1
Q What is the lowest-level language in the computer world?
A The computer’s machine language is the lowest because the machine language, made up of 0s and 1s, is the only language that the computer can understand directly.
Q What are the advantages of high-level programming languages?
A Readability, maintainability, and portability are the main advantages of high-level programming languages.
Q What is C, anyway?
A C is a general-purpose programming language. It’s a high-level language that has advantages such as readability, maintainability, and portability. Also, C allows you to get down to the hardware level to increase the performance speed if needed. A C
compiler is needed to translate programs written in C into machine-understandable code. The portability of C is realized by recompiling the C programs with different C compilers intended for different types of computers.
Q Can I learn C in a short time?
A Yes. C is a small programming language. There are not many C keywords or commands to remember. Also, it’s very easy to read and write C programs because C is a high-level programming language that is close to human languages, especially English. You can learn C in a relatively short time.
Workshop
To help solidify your understanding of this hour’s lesson, you are encouraged to answer the quiz questions provided in the workshop before you move to next lesson. The answers and hints to the questions are given in Appendix D, “Answers to Quiz Questions and Exercises.”
Quiz
1. What are the lowest-level and highest-level languages mentioned in this book?
2. Can a computer directly understand a program written in C? What do you need to translate a program written in C into the machine-understandable code (that is, binary code)?
3. If needed, can a C program be reused in another C program?
4. Why do we need the ANSI standard for the C language?
03 067231861x CH01 4.10.2000 10:59 AM Page 26
04 067231861x CH02 1/25/00 10:42 AM Page 27
HOUR 2
Writing Your First C
Program
Cut your own wood and it will warm you twice.
—Chinese proverb
In Hour 1, “Taking the First Step,” you learned that C is a high-level programming language and that you need a C compiler to translate your C programs into binary code that your computer can understand and execute. In this lesson you’ll write your first C program and learn the basics of a C program, such as
• The #include directive
• Header files
• Comments
• The main() function
• The return statement
• The exit() function
04 067231861x CH02 1/25/00 10:42 AM Page 28
28
Hour 2
• The newline character (\n)
• Translating a C program into an executable file
• Debugging
A Simple C Program
Let’s have a look at your first C program, demonstrated in Listing 2.1. Later in this lesson you’re going to write your own C program for the first time.
LISTING 2.1
A Simple C Program
1: /* 02L01.c: This is my first C program */
2: #include
3:
4: main()
5: {
6: printf (“Howdy, neighbor! This is my first C program.\n”);
7: return 0;
8: }
This is a very simple C program, which is saved in a file called 02L01.c. Note that the name of a C program file must have an extension of .c. If you’ve installed a C compiler and set up the proper development environment, you should be able to compile this C
program, and make it into an executable file. I’ll discuss how to make an executable file later in this chapter.
In the previous hour, you learned how to enter a program into your text editor and save it as a C program file. Here, you may notice that unlike the sample in the last chapter, each line is numbered. This is only done here as a reference for when I discuss what each line of a program does. Unlike other languages such as BASIC, the C language does not have line
LV Lewis
Destiny Patterson
Jack Rogan
Margaret Mallory
Kj Charles
Shannyn Schroeder
Maya Angelou
Unknown
Rue Allyn
Anthony Powell