Home > Backend Development > C++ > body text

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

WBOY
Release: 2023-09-18 23:37:01
forward
1378 people have browsed it

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
}
Copy after login

Output

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

Value of b is 200
Value of b is 10
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template