The comma is frequently used in C as a simple punctuation mark, to separate variable declarations, function arguments, etc. In certain situations, the comma acts as an operator

Files Recovery Software
Home Contact Details Customer Support Download Demo Products  

 
 

The Comma Operator

The comma is frequently used in C as a simple punctuation mark, to separate variable declarations, function arguments, etc. In certain situations, the comma acts as an operator.

You can form an expression by separating two sub expressions with a comma. The result is as follows:

Both expressions are evaluated, with the left expression being evaluated first.

  • The entire expression evaluates to the value of the right expression.
    For example, the following statement assigns the value of b to x, then increments a, and then increments b:
    x = (a++, b++);

C operator precedence (Summary of C operators)

Rank and Associativity

Operators

1(left to right)

() [] -> .

2(right to left)

! ~ ++ -- * (indirection) & (address-of) (type)
sizeof + (unary) - (unary)

3(left to right)

* (multiplication) / %

4(left to right)

+ -

5(left to right)

<< >>

6(left to right)

< <= > >=

7(left to right)

= = !=

8(left to right)

& (bitwise AND)

9(left to right)

^

10(left to right)

|

11(left to right)

&&

12(left to right)

||

13(right to left)

?:

14(right to left)

= += -= *= /= %= &= ^= |= <<= >>=

15(left to right)

   ,

() is the function operator; [] is the array operator.

 


Let us take an example of use of operators:

/* Use Of Operators */

int main()
{
int x = 0, y = 2, z = 1025;
float a = 0.0, b = 3.14159, c = -37.234;

/* incrementing */

x = x + 1; /* This increments x */
x++; /* This increments x */
++x; /* This increments x */
z = y++; /* z = 2, y = 3 */
z = ++y; /* z = 4, y = 4 */

/* decrementing */

y = y - 1; /* This decrements y */
y--; /* This decrements y */
--y; /* This decrements y */
y = 3;
z = y--; /* z = 3, y = 2 */
z = --y; /* z = 1, y = 1 */

/* arithmetic op */

a = a + 12; /* This adds 12 to a */
a += 12; /* This adds 12 more to a */
a *= 3.2; /* This multiplies a by 3.2 */
a -= b; /* This subtracts b from a */
a /= 10.0; /* This divides a by 10.0 */

/* conditional expression */

a = (b >= 3.0 ? 2.0 : 10.5 ); /* This expression */

if (b >= 3.0) /* And this expression */
a = 2.0; /* are identical, both */

else /* will cause the same */
a = 10.5; /* result. */

c = (a > b ? a : b); /* c will have the max of a or b */
c = (a > b ? b : a); /* c will have the min of a or b */

printf("x=%d, y=%d, z= %d\n", x, y, z);
printf("a=%f, b=%f, c= %f", a, b, c);

return 0;
}


and the result of this program will be displayed on the screen as:

x=3, y=1, z=1
a=2.000000, b=3.141590, c=2.000000

Previous page

page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20

 
 

page 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37

 
 

page 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54

 
 

page 55 | 56 | 57 | 58 | 59 | 60

Next page
 
 
Data Recovery Book
 
Chapter 1 An Overview of Data Recovery
Chapter 2 Introduction of Hard Disks
Chapter 3 Logical Approach to Disks and OS
Chapter 4 Number Systems
Chapter 5 Introduction of C Programming
Chapter 6 Introduction to Computer Basics
Chapter 7 Necessary DOS Commands
Chapter 8 Disk-BIOS Functions and Interrupts Handling With C
Chapter 9 Handling Large Hard Disks
Chapter 10 Data Recovery From Corrupted Floppy
Chapter 11 Making Backups
Chapter 12 Reading and Modifying MBR with Programming
Chapter 13 Reading and Modifying DBR with Programming
Chapter 14 Programming for “Raw File” Recovery
Chapter 15 Programming for Data Wipers
Chapter 16 Developing more Utilities for Disks
Appendix Glossary of Data Recovery Terms
 
 
Pro Data Doctor

Home

Products

Contact Details

Customer Support

Download Demo

Terms and Conditions

 
Pro Data Doctor