Explanation of postix, infix and prefix entries

Will anyone be kind enough to explain that infix, postfix, and prefix notation apply to the C programming language?

+3
source share
3 answers

Here is a good discussion of the three terms and how to apply them .

C uses infix notation almost everywhere. For example, you would do:

x = 4 + 2;

However, there are several operations that use prefix notation, such as negation:

x = -y;  // "-" is using prefix notation

Postfix is ​​used for operations such as increment (++):

x = y++;
+5
source

Some examples for each:

Infix:

a + b
a * b

Postfix:

a++
f()
a[i]

Prefix (also called "unary" in C and C ++):

++a
&a
-a
+5
source

C ; "" "" . (sort-of infix) (sort-of prefix). , , , , , , .

, && || , , ; . . -> , , , , , (.. &a.b &(a.b), (&a).b), , .

:

  • ( , , )
  • (a[i])
  • (a->b, d.c)
  • (foo(a,b))
  • (a++, b--)
  • ( C99 - (int []) {1, 2, 3})

, .

:

  • ((int) foo)
  • (sizeof foo, sizeof (int))
  • (-5)
  • (+1)
  • (!expr)
  • (~byte)
  • (&foo)
  • (*ptr)
  • (++foo, --bar)

, , , .

:

  • (a * b, c / d)
  • (a + b, c - d)
  • (a << b, val >> 2)
  • (a < b, c >= d)
  • (a == b, c != d)
  • (a & b, c | d, e ^ f)

, .

In addition to these groups, you also have logical operator expressions ( &&and ||), conditional expressions ( a ? b : c) that have lower priority than binary expressions, assignment expressions ( a = b, c += d), sequential expressions ( a, b, c), and constant expressions ( int a[42], case 5:) that are different from literals classified by postfix expressions.

+1
source

Source: https://habr.com/ru/post/1764190/


All Articles