Syntax Structures Flashcards Preview

Learning C the hard way > Syntax Structures > Flashcards

Flashcards in Syntax Structures Deck (12):
1

An if-statement is your basic logic branching control

i f (TEST) {
CODE;
} e l s e i f (TEST) {
CODE;
} e l s e {
CODE;
}

2

A switch-statement is like an if-statement but works on simple integer constants

s w i t c h (OPERAND) {
c a s e CONSTANT:
CODE;
break ;
d e f a u l t :
CODE;
}

3

A while-loop is your most basic loop

w h i l e (TEST) {
CODE;
}

4

You can also use continue to cause it to loop. Call this form while-continue-loop for now

w h i l e (TEST) {
i f (OTHER_TEST) {
c o n t i n u e ;
} CODE;
}

5

You can also use break to exit a loop. Call this form while-break-loop

w h i l e (TEST) {
i f (OTHER_TEST) {
break ;
} CODE;
}

6

The do-while-loop is an inverted version of a while-loop that runs the code then tests to see
if it should run again

do {
CODE;
} w h i l e (TEST ) ;

7

The for-loop does a controlled counted loop through a (hopefully) fixed number of iterations
using a counter

f o r ( INIT ; TEST ; POST) {
CODE;
}

8

An enum creates a set of integer constants

enum { CONST1, CONST2, CONST3 } NAME;

9

A goto will jumpt to a label, and is only used in a few useful situations like error detection and
exiting

i f (ERROR_TEST) {
goto f a i l ;
}
f a i l :
CODE;

10

A function is defined this way

TYPE NAME(ARG1, ARG2, . . ) {
CODE;
r e t u r n VALUE;
}

11

A typedef defines a new type

t y p e d e f DEFINITION IDENTIFIER ;

12

(A typedef defines a new type) A more concrete form of this is

t y p e d e f unsigned char byte ;