Home  >  Article  >  Backend Development  >  In C language, what types of expressions need to be evaluated?

In C language, what types of expressions need to be evaluated?

WBOY
WBOYforward
2023-09-18 23:37:011381browse

An expression is a combination of operators and operands.

The operands are the data items on which the operation is performed.

Operators perform operations on data

z = 5

In C language, what types of expressions need to be evaluated?

Expression Type

Different types of expressions evaluated in C language are as follows -

  • Primary expression - The operands in this expression can be names , a constant, or any parenthesized expression. For example, c = a (5*b);

  • Postfix expression - In a postfix expression, the operator will come after the operands. For example, ab

  • Prefix expression - In a prefix expression, the operator comes before the operands. For example, ab

  • unary expression - it contains one operator and one operand. For example, a , --b

  • binary expression - it contains 2 operands and 1 operator. For example, a b, c-d

  • ternary expression - It contains 3 operands and 1 operator. For example; Experience 1? Experience 2: Experience 3. If Exp1 is true, Exp2 is executed. Otherwise, execute Exp3.

Example

The following is a C program to calculate an expression in C language -

Live demonstration

#include <stdio.h>
main(){
   int a , b;
   a = 10;
   printf( "Value of b is %d</p><p>", (a == 1) ? 100: 200 );//ternary expression
   printf( "Value of b is %d</p><p>", (a == 10) ? 10: 20 );//ternary expression
}

Output

When the above program is executed, the following results will be produced-

Value of b is 200
Value of b is 10

The above is the detailed content of In C language, what types of expressions need to be evaluated?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete