08.01.2023 Views

Learn to Program with C_ Learn to Program using the Popular C Programming Language ( PDFDrive )

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 2 ■ C – The Basics

token

int

main

Starting from the beginning, we can list the tokens in order:

type

reserved word

identifier

( left bracket, delimiter

) right bracket,

delimiter

{ left brace, delimiter

int reserved word

a identifier

, comma, delimiter

b identifier

, comma, delimiter

sum identifier

; semicolon, delimiter

a identifier

= equals sign, delimiter

14 constant

; semicolon, delimiter

And so on. Therefore we can think of a program as a stream of tokens, which is precisely how

the compiler views it. So that, as far as the compiler is concerned, the above could have been

written like this:

int main() { int a, b, sum;

a = 14; b = 25; sum = a + b;

printf("%d + %d = %d\n", a, b, sum); }

The order of the tokens is exactly the same; to the compiler, it is the same program. To the

computer, only the order of the tokens is important. However, layout and spacing are important to

make the program more readable to human beings.

2.3.1 Spacing Within a Program

Generally speaking, C programs can be written using “free format.” The language does not require

us, for instance, to write one statement on a line. Even a simple statement like

a = 14;

25

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!