|
|
The . (dot) operator and the –> (arrow) operator are used to reference individual members of classes, structures, and unions. The dot operator is applied to the actual object. The arrow operator is used with a pointer to an object. For example, given the following structure:
struct date_time { char date[16]; int time; } tm;
to assign the value "3/12/2003" to the date member of object tm, you would write
strcpy(tm.date, "3/12/2003");
However, if p_tm is a pointer to an object of type date_time, the following statement is used:
strcpy(p_tm->date, "3/12/2003");
The comma operator causes a sequence of operations to be performed. The value of the entire comma expression is the value of the last expression of the comma-separated list. For example, after execution of the following fragment,
y = 15; x = (y=y-5, 50/y);
x will have the value 5 because y’s original value of 15 is reduced by 5 and then that value is divided into 50, yielding 5 as the result. You can think of the comma operator as meaning “do this and this” and so on.
The comma operator is used most often in the for statement. For example,
for(z=10, b=20; z<b; z++, b--) { // ...
Here, z and b are initialized and modified using comma-separated expressions.
|
|