Expression vs Statement in Programming

In this article, we will study two popular terms in the programming language Expression vs Statement and take a look at the differences between the two.

In the programming world, an Expression is a function or a combination of characters, variables, and operators combined together to produce a certain value. These expressions are interpreted by the programming language and converted to produce a value through the process of evaluation. The value obtained is of a primitive type which includes integer, float, boolean, string, or other data types.

For example:

value = a + b/5

Types of Expressions

1. Integral Expressions: As the name suggests, these kinds of expressions return an integer value. Even if a floating value is used in the expression, it is converted into an integer explicitly by the user.

For example:

value = (int)5.0 – b*a

2. Floating Expressions: These kinds of expressions return a floating value. Even if an integral value is used in the expression, it is converted into a floating one explicitly by the user.

For example:

value = (float)5 – b*a

3. Constant Expressions: Constant expressions consist of only constant values which do not change.

For example:

3/6 + 8*3

4. Logical Expressions: These expressions use logical operators (&& and || ) to compute the value of two or more arithmetic expressions.

For example:

a && b || a==b

5. Relational Expressions: These types of expressions return boolean values. Such expressions use relational operators ( <, >, ==, =<, >= ) to compare arithmetic values on either sides of an expression and return a boolean value.

For example:

a + b >= 6

6. Pointer Expressions: Pointers are values that are used to store addresses. Pointer expressions return address values using pointer notations.

For example:

&a , pointer++

7. Bitwise Expressions: These expressions use bitwise operators (<< and >>) to return a value by shifting the bits to the left or right position.

For example:

b << 7 (Shifts left by 7 bits)

These expressions are a part of a broader unit called ‘Statements’. Statements are the combination of characters or words which are used to print the output on the screen. The expressions return a value and these values are printed with the help of statements.

Types of Statements

1. Assignment Statements: These statements are used to assign values to variables.

For example:

value = 1000

2. Increment/Decrement Statements: These statements are used to increment and decrement the value of a variable respectively.

For example:

value++

3. Method call/ Print Statements: These statements are used to call the methods and print them using the print statements.

For example:

System.out.println(value)                     // Statement to print output in Java Language

4. Object Creation Statements: These statements are used to initialize variables or creating objects.

For example:

Integer object = new Integer()                // Statement to create object in Java Language

5. Declaration Statements: These statements are used to declare variables in our programs.

For example:

float value = 785.65

Expression vs Statement

Expression Statement
Expression is a function or a combination of characters, variables, and operators combined together to produce a certain value. The values returned by expressions are printed using statements.
There are 7 types of expressions. There are 5 types of statements.
It uses arithmetic operators and variables to perform its function. It uses simple English statements to perform its function.

Expressions and statements are an important part of any program and most of the codes mainly use them to produce the results. That is why they are much popular among coding languages.

Leave a Comment

Your email address will not be published. Required fields are marked *