-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathopers.html
1441 lines (1404 loc) · 61.5 KB
/
opers.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Operators and Punctuators</TITLE>
<STYLE TYPE="TEXT/CSS">
<!--
.IE3-DUMMY { CONT-SIZE: 100%; }
BODY { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; BACKGROUND-COLOR: #E0E0E0; }
P { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H1 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H2 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H3 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H4 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H5 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H6 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
UL { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
TD { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; BACKGROUND-COLOR: #FFFFFF; }
.NOBORDER { BACKGROUND-COLOR: #E0E0E0; PADDING: 0pt; }
.NOBORDER TD { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; BACKGROUND-COLOR: #E0E0E0; PADDING: 0pt; }
.CODE { FONT-FAMILY: Courier New; }
-->
</STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#E0E0E0">
<FONT SIZE="5"><B>Operators and Punctuators</B></FONT>
<HR>
<UL>
<LI><B><A HREF="#allopers">List of Operators and Punctuators</A></B>
<LI><B><A HREF="#categories">Categories of Operators and Punctuators</A></B>
<LI><B><A HREF="#precedence">Precedence of Operators</A></B>
<LI><B><A HREF="#lvalue">Lvalues and Rvalues</A></B>
</UL>
<HR>
<H2><A NAME="allopers"><U>List of Operators and Punctuators</U></A></H2>
<P>The standard C language provides the following operators and punctuators:
<BR><BR>
<TABLE BORDER CELLPADDING="3" WIDTH="88%">
<TR>
<TD ALIGN="CENTER" WIDTH="11%"><A HREF="#braces"></P>
<PRE>{ }</PRE>
<P></A></TD>
<TD ALIGN="CENTER" WIDTH="11%"><A HREF="#subscr"></P>
<PRE>[ ]</PRE>
<P></A></TD>
<TD ALIGN="CENTER" WIDTH="11%"><A HREF="#parentheses"></P>
<PRE>( )</PRE>
<P></A></TD>
<TD ALIGN="CENTER" WIDTH="11%"><A HREF="#cast"></P>
<PRE>(<I>type</I>)</PRE>
<P></A></TD>
<TD ALIGN="CENTER" WIDTH="11%"><A HREF="#select"></P>
<PRE><B>.</B></PRE>
<P></A></TD>
<TD ALIGN="CENTER" WIDTH="11%"><A HREF="#select"></P>
<PRE>-></PRE>
<P></A></TD>
<TD ALIGN="CENTER" WIDTH="11%"><A HREF="#inc"></P>
<PRE>++</PRE>
<P></A></TD>
<TD ALIGN="CENTER" WIDTH="11%"><A HREF="#dec"></P>
<PRE>--</PRE>
<P></A></TD>
</TR>
<TR>
<TD ALIGN="CENTER" WIDTH="11%"><A HREF="#ref"></P>
<PRE>&</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#deref"></P>
<PRE>*</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#binpm"></P>
<PRE>+</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#binpm"></P>
<PRE>-</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#complement"></P>
<PRE>~</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#logneg"></P>
<PRE>!</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="keywords.html#sizeof"></P>
<PRE>sizeof</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#mult"></P>
<PRE>/</PRE>
<P></A></TD>
</TR>
<TR>
<TD ALIGN="CENTER"><A HREF="#mult"></P>
<PRE>%</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#shift"></P>
<PRE><<</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#shift"></P>
<PRE>>></PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#relop"></P>
<PRE><</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#relop"></P>
<PRE>></PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#relop"></P>
<PRE><=</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#relop"></P>
<PRE>>=</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#equ"></P>
<PRE>==</PRE>
<P></A></TD>
</TR>
<TR>
<TD ALIGN="CENTER"><A HREF="#equ"></P>
<PRE>!=</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#logbit"></P>
<PRE>^</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#logbit"></P>
<PRE>|</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#logbit"></P>
<PRE>&&</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#logbit"></P>
<PRE>||</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#cond"></P>
<PRE>? :</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#assign"></P>
<PRE>=</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#assign"></P>
<PRE>*=</PRE>
<P></A></TD>
</TR>
<TR>
<TD ALIGN="CENTER"><A HREF="#assign"></P>
<PRE>/=</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#assign"></P>
<PRE>%=</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#assign"></P>
<PRE>+=</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#assign"></P>
<PRE>-=</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#assign"></P>
<PRE><<=</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#assign"></P>
<PRE>>>=</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#assign"></P>
<PRE>&=</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#assign"></P>
<PRE>^=</PRE>
<P></A></TD>
</TR>
<TR>
<TD ALIGN="CENTER"><A HREF="#assign"></P>
<PRE>|=</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#comma"></P>
<PRE>,</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="cpp.html#SEC17"></P>
<PRE>#</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="cpp.html#SEC18"></P>
<PRE>##</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#semicolon"></P>
<PRE>;</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#colon"></P>
<PRE>:</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#quotes"></P>
<PRE>" "</PRE>
<P></A></TD>
<TD ALIGN="CENTER"><A HREF="#ellipsis"></P>
<PRE>...</PRE>
<P></A></TD>
</TR>
</TABLE></P>
<P>In addition, GNU C also knows the <A HREF="gnuexts.html#SEC69">typeof</A> operator, and extends
some existing operators.</P>
<HR>
<H2><A NAME="categories"><U>Categories of Operators and Punctuators</U></A></H2>
<UL>
<LI><B><A HREF="#unary">Unary operators</A></B>
<LI><B><A HREF="#binary">Binary operators</A></B>
<LI><B><A HREF="#ternary">Ternary operators</A></B>
<LI><B><A HREF="#punct">Punctuators</A></B>
</UL>
<P>The operators <A HREF="cpp.html#SEC17">#</A> and <A HREF="cpp.html#SEC18">##</A> are
used only by the <A HREF="cpp.html">preprocessor</A>.
<BR><BR>
Depending on context, the same operator can have more than one meaning. For
example, the ampersand (<CODE>'&'</CODE>) can be interpreted as</P>
<UL>
<LI><P>a bitwise AND (<CODE>A & B</CODE>);</P></LI>
<LI><P>an address operator (<CODE>&A</CODE>);</P></LI>
</UL>
<P>In the first case, the <CODE>'&'</CODE> is a unary operator; in the second, the <CODE>'&'</CODE> is a
binary operator. Similarly, the comma <CODE>','</CODE> may act as an operator and as a
punctuator, etc.</P>
<H3><A NAME="unary"><U>Unary operators</U></A></H3>
<UL>
<LI><B><A HREF="#ref">Referencing operator ('&')</A></B>
<LI><B><A HREF="#deref">Dereferencing operator ('*')</A></B>
<LI><B><A HREF="#unarypm">Unary plus and minus operators ('+' and '-')</A></B>
<LI><B><A HREF="#inc">Increment operator ('++')</A></B>
<LI><B><A HREF="#dec">Decrement operator ('--')</A></B>
<LI><B><A HREF="#logneg">Logical negation operator ('!')</A></B>
<LI><B><A HREF="#complement">Bitwise complement operator ('~')</A></B>
</UL>
<P><B>Note:</B> In GNU C the operator '&&' may also be used as unary operator for taking
<A HREF="gnuexts.html#SEC65">addresses of labels</A>.</P>
<H4><A NAME="ref"><U>Referencing operator ('&')</U></A></H4>
<P>In the expression</P>
<PRE>& <I>expr</I>
</PRE>
<P>which means "take the address of the <I>expr</I>",
the <I>expr</I> operand must be one of the following:</P>
<UL>
<LI><P>a function designator;</P></LI>
<LI><P>an <A HREF="#lvalue">lvalue</A> designating an object that is
not a bit field and is not declared with the register storage class specifier.</P></LI>
</UL>
<P>If the operand is of type <I>type</I>, the result is of type "pointer to <I>type</I>".
<BR><BR>
The <CODE>'&'</CODE> symbol is also used in C as a binary <A HREF="#logbit">bitwise AND operator</A>.</P>
<H4><A NAME="deref"><U>Dereferencing operator ('*')</U></A></H4>
<P>In the expression</P>
<PRE>* <I>expr</I>
</PRE>
<P>which means "the object pointed to by <I>expr</I>",
the <I>expr</I> must have type "pointer to <I>type</I>," where <I>type</I> is any
data type. The result of the indirection is of type <I>type</I>.
<BR><BR>
If the operand is of type "pointer to function", the result is a function
designator. If the operand is a pointer to an object, the result is an <A HREF="#lvalue">lvalue</A>
designating that object.
<BR><BR>
In the following situations, the result of indirection is undefined:</P>
<OL>
<LI><P>The <I>expr</I> is a null pointer.</P></LI>
<LI><P>The <I>expr</I> is the address of an
automatic (local) variable and execution of its
block has terminated.</P></LI>
</OL>
<P>You can also use the asterisk as an operator to dereference a pointer, or as
the <A HREF="#mult">multiplication operator</A>. Asterisk may be used also as a
punctuator for creating <A HREF="#asterisk">pointer types</A>.</P>
<H4><A NAME="unarypm"><U>Unary plus and minus operators ('+' and '-')</U></A></H4>
<P>In these unary + - expressions</P>
<PRE>+ <I>expr</I>
- <I>expr</I>
</PRE>
<P>the <I>expr</I> operand must be of arithmetic type.
The result is the value of the operand after any required integral
promotions for the unary plus (<CODE>'+'</CODE>) operator, or
negative of the value of the operand after any
required integral promotions for the unary minus (<CODE>'-'</CODE>) operator.
Floating point negation is internally executed using the <A HREF="timath.html#fneg">fneg</A> function.
<BR><BR>
Note that both '+' and '-' operators also have a <A HREF="#binpm">binary form</A>.</P>
<H4><A NAME="inc"><U>Increment operator ('++')</U></A></H4>
<P>The increment operator may be used as a postincrement or preincrement operator:</P>
<PRE><I>expr</I> ++ (postincrement)
++ <I>expr</I> (preincrement)
</PRE>
<P>The expression is called the operand; it must be of scalar type (arithmetic
or pointer types) and must be a modifiable <A HREF="#lvalue">lvalue</A>.
<BR><BR>
When postincrement operator form is used, the value of the whole expression is the
value of the postfix expression before the increment is applied.
After the postfix expression is evaluated, the operand is incremented by 1.
<BR><BR>
When preincrement operator form is used, the operand is incremented by 1 before the
expression is evaluated; the value of the whole expression is the incremented value
of the operand.
<BR><BR>
The increment value is appropriate to the type of the operand.
Pointer types follow the rules for pointer arithmetic. In other words, the actual
address on which a pointer points to is incremented by the size of the pointed object
(not by 1, except if the pointed object is one byte long), so after the incrementing, the
pointer points to the next object in a sequence (e.g. to a next element in an array, etc.).
<BR><BR>
<B>Note:</B> GNU C extends the pointer arithmetic to be valid even on void pointers and pointers to
functions (see <A HREF="gnuexts.html#SEC79">extended pointer arithmetic</A> for
more info).</P>
<H4><A NAME="dec"><U>Decrement operator ('--')</U></A></H4>
<P>The decrement operator may be used as a postdecrement or predecrement operator:</P>
<PRE><I>expr</I> -- (postdecrement)
-- <I>expr</I> (predecrement)
</PRE>
<P>The decrement operator follows the same rules as the <A HREF="#inc">increment operator</A>,
except that the operand is decremented by 1 after or before the whole
expression is evaluated.</P>
<H4><A NAME="logneg"><U>Logical negation operator ('!')</U></A></H4>
<P>In the expression</P>
<PRE>! <I>expr</I>
</PRE>
<P>the <I>expr</I> operand must be of scalar type (i.e. not an array, a structure or an union).
The result is of type <CODE>int</CODE> and is the logical negation of the operand:</P>
<UL>
<LI><P>0 if the operand is nonzero;</P></LI>
<LI><P>1 if the operand is 0.</P></LI>
</UL>
<P>The expression <CODE>'!<I>expr</I>'</CODE> is equivalent to <CODE>'(0 == <I>expr</I>)'</CODE>.</P>
<H4><A NAME="complement"><U>Bitwise complement operator ('~')</U></A></H4>
<P>In the expression</P>
<PRE>~ <I>expr</I>
</PRE>
<P>the <I>expr</I> operand must be of integral type. The result is the bitwise
complement of the operand after any required integral promotions.
Each 0 bit in the operand is set to 1, and each 1 bit in the operand is set to 0.</P>
<H3><A NAME="binary"><U>Binary operators</U></A></H3>
<UL>
<LI><B><A HREF="#binpm">Binary plus and minus operators ('+' and '-')</A></B>
<LI><B><A HREF="#mult">Multiplicative operators ('*', '/' and '%')</A></B>
<LI><B><A HREF="#shift">Bitwise shift operators ('<<' and '>>')</A></B>
<LI><B><A HREF="#logbit">Logical and bitwise operators ('&', '^', '|', '&&' and '||')</A></B>
<LI><B><A HREF="#assign">Assignment operators ('=' etc.)</A></B>
<LI><B><A HREF="#relop">Relational operators ('<', '>', '<=' and '>=')</A></B>
<LI><B><A HREF="#equ">Equality operators ('==' and '!=')</A></B>
<LI><B><A HREF="#select">Selection (structure-access) operators ('.' and '->')</A></B>
</UL>
<H4><A NAME="binpm"><U>Binary plus and minus operators ('+' and '-')</U></A></H4>
<P>Both <CODE>'+'</CODE> and <CODE>'-'</CODE> uses the same syntax:</P>
<PRE><I>expr1</I> + <I>expr2</I>
<I>expr1</I> - <I>expr2</I>
</PRE>
<P>Note that both '+' and '-' operators also have an <A HREF="#unarypm">unary form</A>.
<BR><BR>
Legal operand types for <I>expr1</I> + <I>expr2</I> are:</P>
<OL>
<LI><P>Both <I>expr1</I> and <I>expr2</I> are of arithmetic type;</P></LI>
<LI><P><I>expr1</I> is of pointer to object type, and <I>expr2</I> is of integral type.</P></LI>
<LI><P><I>expr1</I> is of integral type, and <I>expr2</I> is of pointer to object type;</P></LI>
</OL>
<P>In case 1, the operands are subjected to the standard arithmetical
conversions (for example, <CODE>char</CODE>s are promoted to <CODE>int</CODE>s), and the
result is the arithmetical sum of the operands.
<BR><BR>
In cases 2 and 3, the rules of pointer arithmetic apply. When <I>expr1</I> is of
pointer type (case 2), the actual address on which a pointer points to is incremented by
<I>expr2</I> multiplied by the size of the pointed object (not just by <I>expr2</I>,
except if the pointed object is one byte long). For example, if <I>expr1</I> points
to an array, <I>expr1</I> + 5 points to a fifth element of the array, no matter
how long are the particular elements of the array. The same rules are valid for the case 3.
Assuming that <I>ptr</I> is a pointer to <I>type</I> and that <I>N</I> is an integer,
and assuming that the CPU uses linear addressing (this is true on Motorola 68000, but not
on Intel 8086 for example), expression</P>
<PRE><I>ptr</I> + <I>N</I>
</PRE>
<P>is equal to</P>
<PRE>(<I>type</I> *) ((long) <I>ptr</I> + <I>N</I> * sizeof (<I>type</I>))
</PRE>
<P>Legal operand types for <I>expr1</I> - <I>expr2</I> are:</P>
<OL>
<LI><P>Both <I>expr1</I> and <I>expr2</I> are of arithmetic type;</P></LI>
<LI><P><I>expr1</I> is of pointer to object type, and <I>expr2</I> is integral type;</P></LI>
<LI><P>Both <I>expr1</I> and <I>expr2</I> are pointers to compatible object types;</P></LI>
</OL>
<P>In case 1, the operands are subjected to the standard arithmetic
conversions, and the result is the arithmetic difference of the operands.
<BR><BR>
In cases 2 and 3, the rules of pointer arithmetic apply. When <I>expr1</I> is pointer
and <I>expr2</I> is integral type (case 2), the actual address on which a pointer points to is decremented by
<I>expr2</I> multiplied by the size of the pointed object (not just by <I>expr2</I>,
except if the pointed object is one byte long). For example, if <I>expr1</I> points
to the fifth element of an array, <I>expr1</I> - 2 points to a third element of the array, no matter
how long are the particular elements of the array. When both <I>expr1</I> and <I>expr2</I>
are pointers, the result of the substraction is the difference of actual addresses divided by
the common size of pointed objects. For example, if <I>expr1</I> and <I>expr2</I> point to
two elements of the same array, then <I>expr2</I> - <I>expr1</I> will be equal
to the difference of actual indices of pointed elements.
<BR><BR>
The unqualified type '<I>type</I>' is considered to be compatible with the
qualified types 'const <I>type</I>', 'volatile <I>type</I>', and
'const volatile <I>type</I>'.
<BR><BR>
Floating point addition and substraction are internally executed using the
<A HREF="timath.html#fadd">fadd</A> and <A HREF="timath.html#fsub">fsub</A> functions.
<BR><BR>
<B>Note:</B> GNU C extends the pointer arithmetic to be valid even on void pointers and pointers to
functions (see <A HREF="gnuexts.html#SEC79">extended pointer arithmetic</A> for
more info).</P>
<H4><A NAME="mult"><U>Multiplicative operators ('*', '/' and '%')</U></A></H4>
<P>There are three multiplicative operators in C:</P>
<PRE>* (multiplication: the product of the two operands)
/ (division: the quotient of the first operand divided by the second operand)
% (modulus: the remainder of the first operand divided by the second operand)
</PRE>
<P>They use the following syntax:</P>
<PRE><I>expr1</I> * <I>expr2</I>
<I>expr1</I> / <I>expr2</I>
<I>expr1</I> % <I>expr2</I>
</PRE>
<P>Note that '*' operator also has an <A HREF="#unarypm">unary form</A>, and may be also
used as a punctuator for creating <A HREF="#asterisk">pointer types</A>.
<BR><BR>
Operands for <CODE>'*'</CODE> and <CODE>'/'</CODE> are of arithmetical type, and operands of
<CODE>'%'</CODE> are of integral type.
The usual arithmetic conversions are made on the operands.
For <CODE>'/'</CODE> and <CODE>'%'</CODE>, <I>expr2</I> must be nonzero;
<I>expr2</I> == 0 results in an error (you can't divide by zero).
<BR><BR>
When <I>expr1</I> and <I>expr2</I> are integers and the quotient
is not an integer:</P>
<OL>
<LI><P>If <I>expr1</I> and <I>expr2</I> have the same sign,
<I>expr1</I> / <I>expr2</I> is the largest integer less
than the true quotient, and <I>expr1</I> % <I>expr2</I>
has the sign of <I>expr1</I>.</P></LI>
<LI><P>If <I>expr1</I> and <I>expr2</I> have opposite signs,
<I>expr1</I> / <I>expr2</I> is the smallest integer greater
than the true quotient, and <I>expr1</I> % <I>expr1</I> has
the sign of <I>expr1</I>.</P></LI>
</OL>
<P><B>Note:</B> Rounding is always toward zero.
<BR><BR>
Floating point multiplication and division are internally executed using the
<A HREF="timath.html#fmul">fmul</A> and <A HREF="timath.html#fdiv">fdiv</A> functions; more detailed
info about rules of these operation is given with the description of these functions.</P>
<H4><A NAME="shift"><U>Bitwise shift operators ('<<' and '>>')</U></A></H4>
<P>Bitwise shift operators in C use the following syntax:</P>
<PRE><I>expr1</I> << <I>expr2</I>
<I>expr1</I> >> <I>expr2</I>
</PRE>
<P>In the expressions <I>expr1</I> << <I>expr2</I> and
<I>expr1</I> >> <I>expr2</I>, the operands <I>expr1</I>
and <I>expr2</I> must be of integral type. The normal integral promotions are performed
on <I>expr1</I> and <I>expr2</I>,
and the type of the result is the type of the promoted <I>expr1</I>.
If <I>expr2</I> is negative or is greater than or equal to the width in bits of
<I>expr1</I>, the operation is undefined.
<BR><BR>
The result of the operation <I>expr1</I> << <I>expr2</I>
is the value of <I>expr1</I> left-shifted by <I>expr2</I> bit positions,
zero-filled from the right if necessary.
The result of the operation <I>expr1</I> >> <I>expr2</I>
is the value of <I>expr1</I> right-shifted by <I>expr2</I> bit positions.</P>
<H4><A NAME="logbit"><U>Logical and bitwise operators ('&', '^', '|', '&&' and '||')</U></A></H4>
<P>The C language offers these bitwise and logical operators:</P>
<PRE>& (bitwise AND)
^ (bitwise exclusive OR)
| (bitwise inclusive OR)
&& (logical AND)
|| (logical OR)
</PRE>
<P>They use the following syntax:</P>
<PRE><I>expr1</I> & <I>expr2</I>
<I>expr1</I> ^ <I>expr2</I>
<I>expr1</I> | <I>expr2</I>
<I>expr1</I> && <I>expr2</I>
<I>expr1</I> || <I>expr2</I>
</PRE>
<P>In first three expressions, both operands must be of integral type.
In fourth and fifth expressions, both operands must be of scalar type.
The usual arithmetical conversions are performed on <I>expr1</I> and <I>expr2</I>.
<BR><BR>
For the bitwise operators, each bit in the result is:
<BR><BR>
<TABLE BORDER CELLPADDING="5">
<TR><TD ALIGN="CENTER" COLSPAN="2">Bit value</TD><TD ALIGN="CENTER" COLSPAN="3">Results of</TD></TR>
<TR><TD ALIGN="CENTER"> in <I>expr1</I> </TD><TD ALIGN="CENTER"> in <I>expr2</I> </TD><TD ALIGN="CENTER"><I>expr1</I> & <I>expr2</I></TD><TD ALIGN="CENTER"><I>expr1</I> ^ <I>expr2</I></TD><TD ALIGN="CENTER"><I>expr1</I> | <I>expr2</I></TD></TR>
<TR><TD ALIGN="CENTER">0</TD><TD ALIGN="CENTER">0</TD><TD ALIGN="CENTER">0</TD><TD ALIGN="CENTER">0</TD><TD ALIGN="CENTER">0</TD></TR>
<TR><TD ALIGN="CENTER">1</TD><TD ALIGN="CENTER">0</TD><TD ALIGN="CENTER">0</TD><TD ALIGN="CENTER">1</TD><TD ALIGN="CENTER">1</TD></TR>
<TR><TD ALIGN="CENTER">0</TD><TD ALIGN="CENTER">1</TD><TD ALIGN="CENTER">0</TD><TD ALIGN="CENTER">1</TD><TD ALIGN="CENTER">1</TD></TR>
<TR><TD ALIGN="CENTER">1</TD><TD ALIGN="CENTER">1</TD><TD ALIGN="CENTER">1</TD><TD ALIGN="CENTER">0</TD><TD ALIGN="CENTER">1</TD></TR>
</TABLE>
<BR>
Unlike the bitwise operators, <CODE>'&&'</CODE> and <CODE>'||'</CODE> guarantee left-to-right evaluation.
<I>expr1</I> is evaluated first; if it is zero,
<I>expr1</I> && <I>expr2</I> gives 0 (false), and <I>expr2</I> is
not evaluated at all. With <I>expr1</I> || <I>expr2</I>, if
<I>expr1</I> is nonzero, <I>expr1</I> || <I>expr2</I> gives 1 (true), and
<I>expr2</I> is not evaluated at all.
<BR><BR>
<B>Note:</B> In GNU C the operator '&&' may be also used as unary operator for taking
<A HREF="gnuexts.html#SEC65">addresses of labels</A>.</P>
<H4><A NAME="assign"><U>Assignment operators ('=' etc.)</U></A></H4>
<P>There are 11 assignment operators in C language.
The <CODE>'='</CODE> operator is the simple assignment operator; the other 10
(<CODE>'*='</CODE>, <CODE>'/='</CODE>, <CODE>'%='</CODE>, <CODE>'+='</CODE>, <CODE>'-='</CODE>,
<CODE>'<<='</CODE>, <CODE>'>>='</CODE>, <CODE>'&='</CODE>,
<CODE>'^='</CODE> and <CODE>'|='</CODE>)
are known as compound assignment operators.
All of them use the following syntax:</P>
<PRE><I>expr1</I> <I>assignment-operator</I> <I>expr2</I>
</PRE>
<P>In the expression <I>expr1</I> = <I>expr2</I>,
<I>expr1</I> must be a modifiable <A HREF="#lvalue">lvalue</A>.
The value of <I>expr2</I>, after conversion to the type of <I>expr1</I>, is
stored in the object designated by <I>expr1</I> (replacing
<I>expr1</I>'s previous value). The value of the assignment expression is the value of
<I>expr1</I> after the assignment. That's why multiple assignments like</P>
<PRE>x = y = z = 10;
a = b + 2 * (c = d - 1);
</PRE>
<P>are possible. Note that the assignment expression is not itself an lvalue.
<BR><BR>
For both simple and compound assignment, the operands <I>expr1</I> and <I>expr2</I> must obey
one of the following sets of rules:</P>
<OL>
<LI><P><I>expr1</I> is of qualified or unqualified arithmetic type and
<I>expr2</I> is of arithmetic type.</P></LI>
<LI><P><I>expr1</I> has a qualified or unqualified version
of a structure or union type compatible with the type of <I>expr2</I>.</P></LI>
<LI><P><I>expr1</I> and <I>expr2</I>
are pointers to qualified or unqualified versions of compatible types,
and the type pointed to by the left has all the qualifiers of the type pointed to
by the right.</P></LI>
<LI><P>One of <I>expr1</I> or <I>expr1</I> is a pointer to an object
or incomplete type and the other is a pointer to a qualified or unqualified
version of void. The type pointed to by the left has all the qualifiers of the type
pointed to by the right.</P></LI>
<LI><P><I>expr1</I> is a pointer and <I>expr2</I> is a null pointer constant.</P></LI>
</OL>
<P>The compound assignments are <CODE>'<I>op</I>='</CODE>, where <I>op</I> can be any one of
the ten operator symbols <CODE>'*'</CODE>, <CODE>'/'</CODE>, <CODE>'%'</CODE>, <CODE>'+'</CODE>,
<CODE>'-'</CODE>, <CODE>'<<'</CODE>, <CODE>'>>'</CODE>, <CODE>'&'</CODE>,
<CODE>'^'</CODE> or <CODE>'|'</CODE>. The expression</P>
<PRE><I>expr1</I> <I>op</I>= <I>expr2</I></PRE>
<P>has the same effect as</P>
<PRE><I>expr1</I> = <I>expr1</I> <I>op</I> <I>expr2</I></PRE>
<P>except that the lvalue <I>expr1</I> is evaluated only once. For example, <I>expr1</I> += <I>expr2</I> is
the same as <I>expr1</I> = <I>expr1</I> + <I>expr2</I>.</P>
<H4><A NAME="relop"><U>Relational operators ('<', '>', '<=' and '>=')</U></A></H4>
<P>The relational operators are used to compare relative values.
They use the following syntax:</P>
<PRE><I>expr1</I> < <I>expr2</I>
<I>expr1</I> > <I>expr2</I>
<I>expr1</I> <= <I>expr2</I>
<I>expr1</I> >= <I>expr2</I>
</PRE>
<P>In all relational expressions, the operands must conform to one of the
following sets of conditions:</P>
<OL>
<LI><P>Both <I>expr1</I> and <I>expr2</I> are of arithmetic type.
In this case, the usual arithmetic conversions are performed and the result
is of type <CODE>int</CODE>.</P></LI>
<LI><P>Both <I>expr1</I> and <I>expr1</I> are pointers to qualified or unqualified versions
of compatible object types.</P></LI>
</OL>
<P>When the operands are of arithmetic type:</P>
<UL>
<LI><P><I>expr1</I> < <I>expr2</I> gives 1 (true) if the value of <I>expr1</I>
is less than value of <I>expr2</I>; otherwise, the result is 0 (false).</P></LI>
<LI><P><I>expr1</I> <= <I>expr2</I> gives 1 (true) if the value of <I>expr1</I>
is less than or equal to the value of <I>expr2</I>; otherwise, the result is 0
(false).</P></LI>
<LI><P><I>expr1</I> > <I>expr2</I> gives 1 (true) if the value of <I>expr1</I>
is greater than the value of <I>expr2</I>; otherwise, the result is 0 (false).</P></LI>
<LI><P><I>expr1</I> >= <I>expr2</I> gives 1 (true) if the value of <I>expr1</I>
is greater than or equal to the value of <I>expr2</I>; otherwise, the result is 0 (false).</P></LI>
</UL>
<P>When the operands are of compatible pointer types,
the result depends on the relative addresses of the two
objects being pointed at.
<BR><BR>
Floating point comparisons are internally executed using the
<A HREF="timath.html#fcmp">fcmp</A> function. See the description of this function for
more info about rules of comparisons for floating point values.</P>
<H4><A NAME="equ"><U>Equality operators ('==' and '!=')</U></A></H4>
<P>The operators <CODE>'=='</CODE> and <CODE>'!='</CODE> are used to test for equality or inequality between
arithmetic or pointer values, following rules similar to those for the relational operators.
However, the equality operators have lower precedence than the relational operators,
and you can also compare certain pointer types not allowed with relational operations.
<BR><BR>
In the expressions <I>expr1</I> == <I>expr2</I> and <I>expr1</I> != <I>expr2</I>, the operands must conform to one
of the following sets of conditions:</P>
<OL>
<LI><P>Both <I>expr1</I> and <I>expr2</I> are of arithmetic type.</P></LI>
<LI><P>Both <I>expr1</I> and <I>expr2</I> are pointers to qualified
or unqualified versions of compatible types.</P></LI>
<LI><P>One of <I>expr1</I> and <I>expr2</I> is a pointer to an
object, and the other is a pointer to a qualified or unqualified version of void.
In this case, the pointer to an object is converted to the type
of the other operand (a void pointer).</P></LI>
<LI><P>One of <I>expr1</I> or <I>expr2</I> is a pointer and the other is a null pointer constant.</P></LI>
</OL>
<P>If <I>expr1</I> and <I>expr2</I> have types that are valid operand types for a relational
operator, the same comparison rules as for the relational operators apply.
<BR><BR>
If <I>expr1</I> and <I>expr2</I> are pointers to function types, <I>expr1</I> == <I>expr2</I> gives 1 (true) if they
are both null or if they both point to the same function.
Conversely, if <I>expr1</I> == <I>expr2</I> gives 1 (true), then either <I>expr1</I> and <I>expr2</I> point to the
same function, or they are both null.
<BR><BR>
The expression <I>expr1</I> != <I>expr2</I> follows the same rules, except that the result is 1
(true) if the operands are unequal, and 0 (false) if the operands are equal.
<BR><BR>
Floating point comparisons are internally executed using the
<A HREF="timath.html#fcmp">fcmp</A> function. See the description of this function for
more info about rules of comparisons for floating point values.</P>
<H4><A NAME="select"><U>Selection (structure-access) operators ('.' and '->')</U></A></H4>
<P>The C language supports two selection operators:</P>
<PRE>. (direct member selector)
-> (indirect, or pointer, member selector)
</PRE>
<P>You use the selection operators <CODE>'.'</CODE> and <CODE>'->'</CODE> to access structure and union
members. Suppose that the object <I>s</I> is of struct type <I>S</I> and <I>sptr</I> is a pointer to
<I>s</I>. Then, if <I>m</I> is a member identifier of type <I>M</I> declared in <I>S</I>, these
expressions:</P>
<PRE>s.m
sptr->m
</PRE>
<P>are of type <I>M</I>, and both represent the member object <I>m</I> in <I>s</I>.
<BR><BR>
The expression</P>
<PRE>sptr->m</PRE>
<P>is a convenient synonym for <CODE>(*sptr).m</CODE>.
<BR><BR>
The direct member selector (<CODE>'.'</CODE>) uses the following syntax:</P>
<PRE><I>expresssion</I> . <I>identifier</I>
</PRE>
<P>The <I>expr</I> must be of type union or structure.
The <I>identifier</I> must be the name of a member of that structure or union type.
<BR><BR>
The indirect member operator (<CODE>'->'</CODE>) uses the following syntax:</P>
<PRE><I>expr</I> -> <I>identifier</I>
</PRE>
<P>The <I>expr</I> must be of type pointer to structure or pointer to union.
The <I>identifier</I> must be the name of a member of that structure or union type.
<BR><BR>
The expression with selection operators designates a member of a structure or union object. The
value of the selection expression is the value of the selected member; it will be an
<A HREF="#lvalue">lvalue</A> if and only if the <I>expr</I> is an lvalue. For example,</P>
<PRE>
struct mystruct
{
int i;
char str[21];
long d;
} s, *sptr=&s;
...
s.i = 3; // <I>assign to the 'i' member of mystruct 's'</I>
sptr->d = 12345678; // <I>assign to the 'd' member of mystruct 's'</I>
</PRE>
<P>The expression <CODE>'s.m'</CODE> is an lvalue, provided that <CODE>'s'</CODE> is an lvalue and
<CODE>'m'</CODE> is not an array type.
The expression <CODE>'sptr->m'</CODE> is an lvalue unless <CODE>'m'</CODE> is an array type.
<BR><BR>
If structure <I>B</I> contains a field whose type is structure <I>A</I>, the members of
<I>A</I> can be accessed by two applications of the member selectors.</P>
<H3><A NAME="ternary"><U>Ternary operators</U></A></H3>
<UL>
<LI><B><A HREF="#cond">Conditional operator ('? :')</A></B>
</UL>
<H4><A NAME="cond"><U>Conditional operator ('? :')</U></A></H4>
<P>The conditional operator <CODE>'?:'</CODE> is, in fact, a ternary operator.
It uses the following syntax:</P>
<PRE><I>expr1</I> ? <I>expr2</I> : <I>expr3</I>
</PRE>
<P>In the expression <I>expr1</I> ? <I>expr2</I> : <I>Expr3</I>, the operand <I>expr1</I> must be of scalar type. The
operands <I>expr2</I> and <I>Expr3</I> must obey one of the following sets of rules:</P>
<OL>
<LI><P>Both of arithmetic type. In this case, both <I>expr2</I> and <I>Expr3</I> are subject
to the usual arithmetic conversions, and the type of the result is the common type
resulting from these conversions.</P></LI>
<LI><P>Both of compatible structure or union types.
In this case, the type of the result is the structure or union type of <I>expr2</I> and <I>expr3</I>.</P></LI>
<LI><P>Both of void type. In this case, the result is of type void.</P></LI>
<LI><P>Both of type pointer to qualified or unqualified versions of compatible types.
In this case, the type of the result is pointer to a type qualified with all the
type qualifiers of the types pointed to by both operands.</P></LI>
<LI><P>One operand of pointer type, the other a null pointer constant
In this case, the type of the result is pointer to a type qualified with all the
type qualifiers of the types pointed to by both operands.</P></LI>
<LI><P>One operand of type pointer to an object, the other of type
pointer to a qualified or unqualified version of void.
In this case, the type of the result is that of the non-pointer-to-void operand.</P></LI>
</OL>
<P>
In all cases, <I>expr1</I> is evaluated first. If its value is nonzero (true), then <I>expr2</I>
is evaluated and <I>expr3</I> is ignored (not evaluated at all). If <I>expr1</I> evaluates
to zero (false), then <I>expr3</I> is evaluated and <I>expr2</I> is ignored.
The result of <I>expr1</I> ? <I>expr2</I> : <I>expr3</I> will be the value of whichever of <I>expr2</I> and
<I>expr3</I> is evaluated.
<BR><BR>
<B>Note:</B> GNU C extends the usage of the conditional operator to allow
<A HREF="gnuexts.html#SEC71">omitting the middle operand</A>, so it may be used as
a binary operator too.</P>
<H3><A NAME="punct"><U>Punctuators</U></A></H3>
<UL>
<LI><B><A HREF="#subscr">Array subscript operator ('[...]')</A></B>
<LI><B><A HREF="#parentheses">Parentheses operators ('(...)')</A></B>
<LI><B><A HREF="#braces">Braces ('{...}')</A></B>
<LI><B><A HREF="#eqsign">Equal sign ('=')</A></B>
<LI><B><A HREF="#comma">Comma operator and punctuator (',')</A></B>
<LI><B><A HREF="#semicolon">Semicolon (';')</A></B>
<LI><B><A HREF="#colon">Colon (':')</A></B>
<LI><B><A HREF="#asterisk">Asterisk ('*')</A></B>
<LI><B><A HREF="#quotes">Quotes ('"..."')</A></B>
<LI><B><A HREF="#ellipsis">Ellipsis ('...')</A></B>
<LI><B><A HREF="#cast">Typecast ('(type)')</A></B>
</UL>
<P>Most of these punctuators also function as operators.</P>
<H4><A NAME="subscr"><U>Array subscript operator ('[...]')</U></A></H4>
<P>Brackets indicate single and multidimensional array subscripts. When used
as an operator, the expression</P>
<PRE><I>expr1</I>[<I>expr2</I>]
</PRE>
<P>is defined exactly as</P>
<PRE>*((<I>expr1</I>) + (<I>expr2</I>))
</PRE>
<P>where either <I>expr1</I> is a pointer and <I>expr2</I> is an integer,
or <I>expr1</I> is an integer and <I>expr2</I> is a pointer. Of course,
the addition is performed in according to the pointer arithmetic rules
(see <A HREF="#binpm">binary plus</A> for more info).
<BR><BR>
Note that every array name, if used alone (without the array subscript operator), is
automatically interpreted as a pointer to the first element of the array.
<BR><BR>
When used as a punctuator, brackets are used for creating array types (see
<A HREF="#asterisk">asterisk</A> for more info).
<BR><BR>
<B>Note:</B> The GNU C extends the usage of square brackets to allow
<A HREF="gnuexts.html#SEC82">labeling elements in initializers</A>.</P>
<H4><A NAME="parentheses"><U>Parentheses operators ('(...)')</U></A></H4>
<P>Parentheses operators do the following:</P>
<UL>
<LI><P>group expressions (when necessary to change precedence);</P></LI>
<LI><P>isolate conditional expressions;</P></LI>
<LI><P>indicate function calls and function parameters.</P></LI>
</UL>
<P>Note that parentheses are also the part of the <A HREF="#cast">TypeCast</A> operator.
<BR><BR>
When used as function-call operators, parentheses use the following syntax:</P>
<PRE><I>expr</I> (<I>arg-expression-list</I>)
</PRE>
<P>This is a call to the function given by the <I>expr</I>, which can be either
the function name, or an expression which evaluates to a pointer-to-function
type. In the second case, the function call is in fact translated to</P>
<PRE>(* <I>expr</I>) (<I>arg-expression-list</I>)
</PRE>
<P><I>arg-expression-list</I> is a comma-delimited list of expressions of
any type representing the actual (or real) function arguments. The value of the
function call expression, if it has a value, is determined by the
<CODE>return</CODE> statement in the function definition.
<BR><BR>
<I>arg-expression-list</I> may even be empty, which is necessary when you
need to call an argument-less function:</P>
<PRE><I>expr</I> ()
</PRE>
<P>Note that every function name, if used alone (without the parentheses operator), is
automatically interpreted as a pointer to the function.
<BR><BR>
When used as a punctuator, parentheses are used for creating function types (see
<A HREF="#asterisk">asterisk</A> for more info).</P>
<H4><A NAME="braces"><U>Braces ('{...}')</U></A></H4>
<P>The { } braces indicate the start and end of a compound statement. Each sequence
of statements (terminated by <A HREF="#semicolon">semicolons</A>) is treated as
a single statement, called compound statement. Compound statements may have its
own local variables as well.
<BR><BR>
Braces are also used in declaration of <A HREF="keywords.html#enum">enumerations</A>,
<A HREF="keywords.html#struct">structures</A> and <A HREF="keywords.html#union">unions</A>,
as well as for function definitions. For example:</P>
<PRE>int square (int x); // <I>This is a function prototype</I>
int square (int x) {return x*x;} // <I>This is a function definition</I>
</PRE>
<P><B>Note:</B> The GNU C extends the usage of braces (together with <A HREF="#parentheses">parentheses</A>)
to allow making <A HREF="gnuexts.html#SEC63">statement expressions</A>. They are also used
in <A HREF="gnuexts.html#SEC81">cast constructors</A>, which are yet another
GNU C extension.</P>
<H4><A NAME="eqsign"><U>Equal sign ('=')</U></A></H4>
<P>The <CODE>'='</CODE> (equal sign) used as a punctuator separates variable declarations from initialization
lists. For example,</P>
<PRE>int array[5] = { 1, 2, 3, 4, 5 };
char *name = "Fred";
int x = 12;
</PRE>
<P>In a C function, no code can precede any variable declarations. Note that the GNU C,
in opposite to other C dialects, allow <A HREF="gnuexts.html#SEC80">non-constant
initializers</A> (like in C++).
<BR><BR>
The equal sign is also used in <A HREF="keywords.html#enum">enumerations</A>:</P>
<PRE>enum colors {Blue = 1, Red = 2, Green = 4, Light = 8};
</PRE>
<P>It is also used as the <A HREF="#assign">assignment operator</A> in expressions:</P>
<PRE>a = b + c;
</PRE>
<P>or even:</P>
<PRE>a = b + 2 * (c = d - 1);
</PRE>
<P><B>Note:</B> The GNU C extends the usage of equal sign (as a punctuator) to allow
<A HREF="gnuexts.html#SEC82">labeling elements in initializers</A>.</P>
<H4><A NAME="comma"><U>Comma operator and punctuator (',')</U></A></H4>
<P>The comma, used as a punctuator, separates the elements of a function argument list,
the elements in array or struct initializers, or the variables in a data declaration.
The comma is also used as an operator in comma expressions. Mixing the two
uses of comma is legal, but you must use parentheses to distinguish them.
<BR><BR>
When used as an operator, the comma operator uses the following syntax:</P>
<PRE><I>expr1</I>, <I>expr2</I>
</PRE>
<P>The left operand <I>expr1</I> is evaluated as a void expression
(i.e. it is ignored if not contain side effects), then <I>expr2</I> is evaluated
to give the result and type of the comma expression. So, the result is just <I>expr2</I>.
By recursion, the expression</P>
<PRE><I>expr1</I>, <I>expr2</I>, ..., <I>ExprN</I>
</PRE>
<P>results in the left-to-right evaluation of each <I>Expr-i</I>, with the value and type
of <I>ExprN</I> giving the result of the whole expression. Comma operator is usually used
in for-loops for multiple initializations. For example,</P>
<PRE>for (i = 0, j = 1024; i + j < 5; i++, j /= 2) ...
</PRE>
<P>It also may be used to avoid making compound statements in simple conditional statements.
For example,</P>
<PRE>if (x > 10) i = 1, j = 2, k = 3;
</PRE>
<P>have the same effect as</P>
<PRE>if (x > 10)
{
i = 1; j = 2; k = 3;
}
</PRE>
<P>To avoid ambiguity with the commas used in function argument and initializer
lists, parentheses must be used. For example,</P>
<PRE>func(i, (j = 1, j + 4), k);
</PRE>
<P>calls <CODE>'func'</CODE> with three arguments, not four. The arguments are
<CODE>'i'</CODE>, <CODE>'5'</CODE>, and <CODE>'k'</CODE>.</P>
<H4><A NAME="semicolon"><U>Semicolon (';')</U></A></H4>
<P>The semicolon is a statement terminator. It is also used to separate three
expressions which are parts of a for-loop.
<BR><BR>
Any legal C expression (including the empty expression) followed by ; is
interpreted as a statement, known as an expression statement.
The expression is evaluated and its value is discarded. If the expression
statement has no side effects, it will be simply ignored.
<BR><BR>
Semicolons are often used to create an empty statement. For example, the body
of the following for-loop (which searches for a first non-zero element in the
array) is an empty statement:</P>
<PRE>for (i = 0; i < max || !a[i]; i++);
</PRE>
<H4><A NAME="colon"><U>Colon (':')</U></A></H4>
<P>Use the colon (<CODE>':'</CODE>) to indicate a labeled statement:</P>
<PRE>start:
x=0;
...
goto start;
</PRE>
<P>Special case of labels are case-labels, which are used in multiple selection statements,
for example,</P>
<PRE>switch (a)
{
case 1:
puts("One");
break;
case 2:
puts("Two");
break;
...
default:
puts("None of the above!");
}
</PRE>
<P><B>Note:</B> The GNU C allows creating of <A HREF="gnuexts.html#SEC64">local labels</A>, which are
useful in macro definitions.</P>
<H4><A NAME="asterisk"><U>Asterisk ('*')</U></A></H4>
<P>The asterisk (<CODE>'*'</CODE>) in a variable expression creates a pointer to a type.
For example,</P>
<PRE>int a, *b;
</PRE>
<P>In this example <CODE>'a'</CODE> is an integer, but <CODE>'b'</CODE> is a pointer to
an integer.
<BR><BR>
Punctuators asterisk, <A HREF="#subscr">brackets</A> and <A HREF="#parentheses">parentheses</A>
may be mixed together to create very complex data types (which are sometimes very hard to
understand). When mixed together, parentheses have the greatest precedence, then brackets,
and finally, asterisks. This will be illustrated with a set of examples, which are given in
the following table:
<BR><BR>
<TABLE BORDER CELLPADDING="5">
<TR><TD VALIGN="TOP"></P>
<PRE>int x;</PRE>
<P></TD>
<TD VALIGN="TOP">A simple integer</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int x[5];</PRE>
<P></TD>
<TD VALIGN="TOP">An array (with 5 elements) of integers</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int x[5][6];</PRE>
<P></TD>
<TD VALIGN="TOP">An array (with 5 elements) of arrays (with 6 elements) of integers;
such "array of arrays" may be interpreted as a 5x6 matrix</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int *x;</PRE>
<P></TD>
<TD VALIGN="TOP">A pointer to an integer</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int *x[5];</PRE>
<P></TD>
<TD VALIGN="TOP">An array of pointers to integers</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int x();</PRE>
<P></TD>
<TD VALIGN="TOP">A function (more precise, a prototype of a function) which returns an integer</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int x(int a);</PRE>
<P></TD>
<TD VALIGN="TOP">A function which accepts one integer argument, and which returns an integer</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int x(int a,int *b);</PRE>
<P></TD>
<TD VALIGN="TOP">A function which accepts two arguments, the first one is an integer, and second
one is a pointer to an integer, and which returns an integer</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int x(int,int*);</PRE>
<P></TD>
<TD VALIGN="TOP">The same as above, but actual names of arguments may be omitted in function
prototypes (but not in function definitions)</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int *x();</PRE>
<P></TD>
<TD VALIGN="TOP">A function which returns a pointer to an integer</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int *x(int);</PRE>
<P></TD>
<TD VALIGN="TOP">A function which accepts one integer argument, and which returns a pointer to an integer</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int **x;</PRE>
<P></TD>
<TD VALIGN="TOP">A pointer to a pointer to an integer (this declaration is logically equivalent
with the next one)</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int *x[];</PRE>
<P></TD>
<TD VALIGN="TOP">An array of unknown size of pointers to integers (this declaration is
logically equivalent with the previous one)</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int (*x)[5];</PRE>
<P></TD>
<TD VALIGN="TOP">A pointer to an array (with 5 elements) of integers</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int (*x)();</PRE>
<P></TD>
<TD VALIGN="TOP">A pointer to a function which returns an integer</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int (*x)(int,int);</PRE>
<P></TD>
<TD VALIGN="TOP">A pointer to a function which accepts two integer arguments and which returns an integer</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int (*x[5])();</PRE>
<P></TD>
<TD VALIGN="TOP">An array of pointers to a function which returns an integer</TD></TR>
<TR><TD VALIGN="TOP"></P>
<PRE>int (*x(*x())[5])();</PRE>
<P></TD>
<TD VALIGN="TOP">A function which returns a pointer to an array of pointers to a function which returns an integer</TD></TR>
<TR><TD VALIGN="TOP"></P>