Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C For Dummies 2nd Ed 2004.pdf
Скачиваний:
43
Добавлен:
17.08.2013
Размер:
8.34 Mб
Скачать

34

Part I: Introduction to C Programming

Functions such as printf() require a set of parentheses and lots of stuff inside the parentheses. (Don’t fret over this statement right now; just nod your head and smile in agreement, “Yes, printf() does require lots of stuff.”)

By the way, the fact that printf() is a C function and not a keyword is

why the #include <stdio.h> thing is required at the beginning of a pro­ gram. The STDIO.H file contains instructions telling the compiler what exactly printf() is and does. If you edit out the #include <stdio.h> line, the compiler produces a funky “I don’t know what to do with this printf() thing” type of error.

Other C Language Components

The C language has many other parts, making it look rather bizarre to the new programmer. Right now, all that’s standing between ignorance and knowledge is time, so don’t dwell on what you don’t know. Instead, keep these few points rolling around in your mind, like so many knowledge nuggets:

The C language uses words — keywords, functions, and so forth — as its most basic elements.

Included with the words are symbols. Sometimes these symbols are called operators, and at other times they’re called something else. For example, the plus sign (+) is used in C to add things.

The words have options and rules about how they’re used. These rules are all referenced in the C reference material that came with your compiler. You don’t have to memorize all of them, though a few of them become second nature to you as you study and use C.

Parentheses are used to group some of the important items required by C words.

The words are put together to create statements, which are similar to sentences in English. The statements all end with a semicolon.

Braces are used to group parts of a program. Some words use braces to group their belongings, and all the separate functions you create within a program are grouped by braces. In Figure 3-1 and in all your C programs in the first two chapters, for example, the braces have been used to con­ tain the belongings of the main() function.

All this stuff put together (and more stuff I dare not discuss at this point) makes up the syntax of the C language. Syntax is how languages are put together.

Chapter 3: C Straight 35

Pop Quiz!

1.The core function in every C language program is called

A.numero_uno().

B.main().

C.primus().

D.core().

2.C language keywords are

A.The “words” of the C language.

B.Held together with string and earwax.

C.Uttered only in candlelit reverence by the C Language Gurus.

D.As numerous as the stars and nearly as distant.

3.In addition to keywords are

A.Functions, such as printf().

B.Operators, such as +, -, and other weird things.

C.Curly braces or brackets, angle brackets — all sorts of brackets. Man, do we have a bracket problem!

D.Probably all of the above.

4.Functions require parentheses because

A.They talk in whispers.

B.The parentheses keep the function warm.

C.The parentheses hold various things required by or belonging to the function.

D.What’s a function?

5.A telltale sign of any C program is its curly braces. Using what you know of C, draw in the braces where they should appear in the following program:

int main()

___

printf(“Goodbye, cruel world!\n”); return(0);

___

Answers on page 516.