• Assignment Statement

An Assignment statement is a statement that is used to set a value to the variable name in a program .

Assignment statement allows a variable to hold different types of values during its program lifespan. Another way of understanding an assignment statement is, it stores a value in the memory location which is denoted by a variable name.

Assignment Statement Method

The symbol used in an assignment statement is called as an operator . The symbol is ‘=’ .

Note: The Assignment Operator should never be used for Equality purpose which is double equal sign ‘==’.

The Basic Syntax of Assignment Statement in a programming language is :

variable = expression ;

variable = variable name

expression = it could be either a direct value or a math expression/formula or a function call

Few programming languages such as Java, C, C++ require data type to be specified for the variable, so that it is easy to allocate memory space and store those values during program execution.

data_type variable_name = value ;

In the above-given examples, Variable ‘a’ is assigned a value in the same statement as per its defined data type. A data type is only declared for Variable ‘b’. In the 3 rd line of code, Variable ‘a’ is reassigned the value 25. The 4 th line of code assigns the value for Variable ‘b’.

Assignment Statement Forms

This is one of the most common forms of Assignment Statements. Here the Variable name is defined, initialized, and assigned a value in the same statement. This form is generally used when we want to use the Variable quite a few times and we do not want to change its value very frequently.

Tuple Assignment

Generally, we use this form when we want to define and assign values for more than 1 variable at the same time. This saves time and is an easy method. Note that here every individual variable has a different value assigned to it.

(Code In Python)

Sequence Assignment

(Code in Python)

Multiple-target Assignment or Chain Assignment

In this format, a single value is assigned to two or more variables.

Augmented Assignment

In this format, we use the combination of mathematical expressions and values for the Variable. Other augmented Assignment forms are: &=, -=, **=, etc.

Browse more Topics Under Data Types, Variables and Constants

  • Concept of Data types
  • Built-in Data Types
  • Constants in Programing Language 
  • Access Modifier
  • Variables of Built-in-Datatypes
  • Declaration/Initialization of Variables
  • Type Modifier

Few Rules for Assignment Statement

Few Rules to be followed while writing the Assignment Statements are:

  • Variable names must begin with a letter, underscore, non-number character. Each language has its own conventions.
  • The Data type defined and the variable value must match.
  • A variable name once defined can only be used once in the program. You cannot define it again to store other types of value.
  • If you assign a new value to an existing variable, it will overwrite the previous value and assign the new value.

FAQs on Assignment Statement

Q1. Which of the following shows the syntax of an  assignment statement ?

  • variablename = expression ;
  • expression = variable ;
  • datatype = variablename ;
  • expression = datatype variable ;

Answer – Option A.

Q2. What is an expression ?

  • Same as statement
  • List of statements that make up a program
  • Combination of literals, operators, variables, math formulas used to calculate a value
  • Numbers expressed in digits

Answer – Option C.

Q3. What are the two steps that take place when an  assignment statement  is executed?

  • Evaluate the expression, store the value in the variable
  • Reserve memory, fill it with value
  • Evaluate variable, store the result
  • Store the value in the variable, evaluate the expression.

Customize your course in 30 seconds

Which class are you in.

tutor

Data Types, Variables and Constants

  • Variables in Programming Language
  • Concept of Data Types
  • Declaration of Variables
  • Type Modifiers
  • Access Modifiers
  • Constants in Programming Language

Leave a Reply Cancel reply

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

Download the App

Google Play

Logo for Rebus Press

Want to create or adapt books like this? Learn more about how Pressbooks supports open publishing practices.

Kenneth Leroy Busbee

An assignment statement sets and/or re-sets the value stored in the storage location(s) denoted by a variable name; in other words, it copies a value into the variable. [1]

The assignment operator allows us to change the value of a modifiable data object (for beginning programmers this typically means a variable). It is associated with the concept of moving a value into the storage location (again usually a variable). Within most programming languages the symbol used for assignment is the equal symbol. But bite your tongue, when you see the = symbol you need to start thinking: assignment. The assignment operator has two operands. The one to the left of the operator is usually an identifier name for a variable. The one to the right of the operator is a value.

Simple Assignment

The value 21 is moved to the memory location for the variable named: age. Another way to say it: age is assigned the value 21.

Assignment with an Expression

The item to the right of the assignment operator is an expression. The expression will be evaluated and the answer is 14. The value 14 would be assigned to the variable named: total_cousins.

Assignment with Identifier Names in the Expression

The expression to the right of the assignment operator contains some identifier names. The program would fetch the values stored in those variables; add them together and get a value of 44; then assign the 44 to the total_students variable.

  • cnx.org: Programming Fundamentals – A Modular Structured Approach using C++
  • Wikipedia: Assignment (computer science) ↵

Programming Fundamentals Copyright © 2018 by Kenneth Leroy Busbee is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License , except where otherwise noted.

Share This Book

CS101: Introduction to Computer Science I

assignment statement meaning in computer language

Variables and Assignment Statements

Read this chapter, which covers variables and arithmetic operations and order precedence in Java.

9. Assignment Statements

No. The incorrect splittings are highlighted in red:

Assignment Statement

So far, the example programs have been using the value initially put into a variable. Programs can change the value in a variable. An  assignment statement  changes the value that is held in a variable. The program uses an assignment statement.

The assignment statement puts the value 123 into the variable. In other words, while the program is executing there will be a 64 bit section of memory that holds the value 123.

Remember that the word "execute" is often used to mean "run". You speak of "executing a program" or "executing" a line of the program.

Question 10:

Variables and Assignment Statements

  • First Online: 23 August 2018

Cite this chapter

Book cover

  • Irv Kalb 2  

5973 Accesses

This chapter covers the following topics:

A sample Python program

Building blocks of programming

Four types of data

What a variable is

Rules for naming variables

Giving a variable a value with an assignment statement

A good way to name variables

Special Python keywords

Case sensitivity

More complicated assignment statements

Print statements

Basic math operators

Order of operations and parentheses

A few small sample programs

Additional naming conventions

How to add comments in a program

Use of “whitespace”

Errors in programs

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
  • Available as EPUB and PDF
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and affiliations.

Mountain View, California, USA

You can also search for this author in PubMed   Google Scholar

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Irv Kalb

About this chapter

Kalb, I. (2018). Variables and Assignment Statements. In: Learn to Program with Python 3. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-3879-0_2

Download citation

DOI : https://doi.org/10.1007/978-1-4842-3879-0_2

Published : 23 August 2018

Publisher Name : Apress, Berkeley, CA

Print ISBN : 978-1-4842-3878-3

Online ISBN : 978-1-4842-3879-0

eBook Packages : Professional and Applied Computing Apress Access Books Professional and Applied Computing (R0)

Share this chapter

Anyone you share the following link with will be able to read this content:

Sorry, a shareable link is not currently available for this article.

Provided by the Springer Nature SharedIt content-sharing initiative

  • Publish with us

Policies and ethics

  • Find a journal
  • Track your research

2. Assignment Statements

One of the most common statements (instructions) in C++ is the assignment statement , which has the form:

= is the assignment operator . This statement means that the expression on the right hand side should be evaluated, and the resulting value stored at the desitnation named on the left. Most often this destination is a variable name, although in come cases the destination is itself arrived at by evaluating an expression to compute where we want to save the value.

Some examples of assignment statements would be

Now, a few things worth noting:

These statements manipulate 4 different variables: pi , r , areaOfCircle and circumferenceOfCircle .

We have to assume that r already contains a sensible value if we are to believe that these assignments will do anythign useful.

The last two only make sense if the first assignment has been performed already. Luckily, when we arrange statements into a straightline arrangement like this, they are performed in that same order.

Note that we have reused pi in two different statements. We didn't need to do this. I could instead have written

but I think the original version is easier to read.

When using variables on either side of an assignment, we need to declare the variables first:

Actually, we can combine the operations of declaring a varable and of assigning its first, or initial value:

Technically these are no longer assignments. Instead they are called initialization statements. But the effect is much the same.

I actually prefer this second, combined version, by the way. One of the more common programming errors is declarign a variable, forgetting to assign it a value, but later trying to use it in a computation anyway. If the variable isn't initialized, you basically get whatever bits happened to be left in memory by the last program that used that address. So you wind up taking an essentially random group of bits, feeding them as input to a calculation, feeding that result into another calculation, and so on, until eventually some poor schmuck gets a telephone bill for $1,245,834 or some piece of expensive computer-controlled machinery tears itself to pieces.

By getting into a habit of always initializing variables while declaring them, I avoid most of the opportunities for ever making this particular mistake.

In the Forum:

no comments available

Variable Assignment

To "assign" a variable means to symbolically associate a specific piece of information with a name. Any operations that are applied to this "name" (or variable) must hold true for any possible values. The assignment operator is the equals sign which SHOULD NEVER be used for equality, which is the double equals sign.

The '=' symbol is the assignment operator. Warning, while the assignment operator looks like the traditional mathematical equals sign, this is NOT the case. The equals operator is '=='

Design Pattern

To evaluate an assignment statement:

  • Evaluate the "right side" of the expression (to the right of the equal sign).
  • Once everything is figured out, place the computed value into the variables bucket.

We've already seen many examples of assignment. Assignment means: "storing a value (of a particular type) under a variable name" . Think of each assignment as copying the value of the righthand side of the expression into a "bucket" associated with the left hand side name!

Read this as, the variable called "name" is "assigned" the value computed by the expression to the right of the assignment operator ('=');

Now that you have seen some variables being assigned, tell me what the following code means?

The answer to above questions: the assignment means that lkjasdlfjlskdfjlksjdflkj is a variable (a really badly named one), but a variable none-the-less. jlkajdsf and lkjsdflkjsdf must also be variables. The sum of the two numbers held in jlkajdsf and lkjsdflkjsdf is stored in the variable lkjasdlfjlskdfjlksjdflkj.

Examples of builtin Data and Variables (and Constants)

For more info, use the "help" command: (e.g., help realmin);

Examples of using Data and Variable

Pattern to memorize, assignment pattern.

The assignment pattern creates a new variable, if this is the first time we have seen the "name", or, updates the variable to a new value!

Read the following code in English as: First, compute the value of the thing to the right of the assignment operator (the =). then store the computed value under the given name, destroying anything that was there before.

Or more concisely: assign the variable "name" the value computed by "right_hand_expression"

Library homepage

  • school Campus Bookshelves
  • menu_book Bookshelves
  • perm_media Learning Objects
  • login Login
  • how_to_reg Request Instructor Account
  • hub Instructor Commons
  • Download Page (PDF)
  • Download Full Book (PDF)
  • Periodic Table
  • Physics Constants
  • Scientific Calculator
  • Reference & Cite
  • Tools expand_more
  • Readability

selected template will load here

This action is not available.

Engineering LibreTexts

1.4: Java Language Elements

  • Last updated
  • Save as PDF
  • Page ID 15059

  • Ralph Morelli & Ralph Wade
  • Trinity College

In this section we will introduce some of the key elements of the Java language by describing the details of a small program. We will look at how a program is organized and what the various parts do. Our intent is to introduce important language elements, many of which will be explained in greater detail in later sections.

The program we will study is a Java version of the traditional HelloWorld program—”traditional” because practically every introductory programming text begins with it. When it is run, the HelloWorld program (Fig. [fig:helloworld]) just displays the greeting “Hello, World!” on the console.

The first thing to notice about the HelloWorld program is the use of comments. A comment is a non-executable portion of a program that is used to document the program. Because comments are not executable instructions they are just ignored by the compiler. Their sole purpose is to make the program easier for the programmer to read and understand.

The HelloWorld program contains examples of two types of Java comments. Any text contained within /* and */ is considered a comment. As you can see in HelloWorld, this kind of comment can extend over several lines and is sometimes called a multiline comment. A second type of comment is any text that follows double slashes (//) on a line. This is known as a single-line comment because it cannot extend beyond a single line.

When the compiler encounters the beginning marker (/*) of a multiline comment, it skips over everything until it finds a matching end marker (*/). One implication of this is that it is not possible to put one multiline comment inside of another. That is, one comment cannot be nested , or contained, within another comment. The following code segment illustrates the rules that govern the use of /* and */:

As you can see from this example, it is impossible to begin a new comment inside an already-started comment because all text inside the first comment, including /*, is ignored by the compiler.

Multiline comments are often used to create a comment block that provides useful documentation for the program. In HelloWorld, the program begins with a comment block that identifies the name of file that contains the program and its author and provides a brief description of what the program does.

For single-line comments, double slashes (//) can be inserted anywhere on a line of code. The result is that the rest of the line is ignored by the compiler. We use single-line comments throughout the HelloWorld program to provide a running commentary of its language elements.

A well-written program should begin with a comment block that provides the name of the program, its author, and a description of what the program does.

Program Layout

Another thing to notice about the program is how neatly it is arranged on the page. This is done deliberately so that the program is easy to read and understand. In Java, program expressions and statements may be arranged any way the programmer likes. They may occur one per line, several per line, or one per several lines. But the fact that the rules governing the layout of the program are so lax makes it all the more important that we adopt a good programming style, one that will help make programs easy to read.

So look at how things are presented in HelloWorld. Notice how beginning and ending braces, and , are aligned, and note how we use single-line comments to annotate ending braces. Braces are used to mark the beginning and end of different blocks of code in a Java program and it can sometimes be difficult to know which beginning and end braces are matched up. Proper indentation and the use of single-line comments make it easier to determine how the braces are matched up.

Similarly, notice how indentation is used to show when one element of the program is contained within another element. Thus, the elements of the HelloWorld class are indented inside of the braces that mark the beginning and end of the class. And the statements in the main() method are indented to indicate that they belong to that method. Use of indentation in this way, to identify the program’s structure, makes the program easier to read and understand.

Keywords and Identifiers

The Java language contains 48 predefined keywords (Table [tab:keywords]). These are words that have special meaning in the language and whose use is reserved for special purposes. For example, the keywords used in the HelloWorldprogram (Fig. [fig:helloworld]) are: class, extends, private, public, static, and void.

Because their use is restricted, keywords cannot be used as the names of methods, variables, or classes. However, the programmer can make up his or her own names for the classes, methods, and variables that occur in the program, provided that certain rules and conventions are followed.

The names for classes, methods, and variables are called identifiers, which follow certain syntax rules:

Names in Java are case sensitive , which means that two different identifiers may contain the same letters in the same order. For example, thisVar and ThisVar are two different identifiers.

In addition to the syntax rule that governs identifiers, Java programmers follow certain style conventions in making up names for classes, variables, and methods. By convention, class names in Java begin with a capital letter and use capital letters to distinguish the individual words in the name—for example, HelloWorld and TextField. Variable and method names begin with a lowercase letter but also use capital letters to distinguish the words in the name—for example, main(), greeting, greet(), getQuestion(), and getAnswer(). The advantage of this convention is that it is easy to distinguish the different elements in a program—classes, methods, variables—just by how they are written. (For more on Java style conventions, see Appendix A.).

Another important style convention followed by Java programmers is to choose descriptive identifiers when naming classes, variables, and methods. This helps to make the program more readable.

To make your program more readable, choose names that describe the purpose of the class, variable, or method.

Data Types and Variables

A computer program wouldn’t be very useful if it couldn’t manipulate different kinds of data, such as numbers and strings. The operations that one can do on a piece of data depend on the data’s type. For example, you can divide and multiply numbers, but you cannot do this with strings. Thus, every piece of data in a Java program is classified according to its data type .

Broadly speaking, there are two categories of data in Java: various types of objects and eight different types of built-in primitive data types . In addition to new types of objects that are created by programmers, Java has many different types of built-in objects. Two types that we will encounter in this chapter are the String and PrintStream objects. Java’s primitive types include three integer types, three real number types, a character type, and a boolean type with values true and false. The names of the primitive types are keywords like int for one integer type, double for one real number type, and boolean.

As we noted in Chapter [chapter-intro], a variable is a named storage location that can store a value of a particular type. Practically speaking, you can think of a variable as a special container into which you can place values, but only values of a certain type (Fig. [fig:vars]). For example, an int variable can store values like 5 or -100. A String variable can store values like “Hello”. (Actually, this is not the full story, which is a little more complicated, but we will get to that in Chapter [chapter-objects].)

In the HelloWorld class, the instance variable greeting (line 8) stores a value of type String. In the main() method, the variable helloworld is assigned a HelloWorld object (line 16).

A literal value is an actual value of some type that occurs in a program. For example, a string enclosed in double quotes, such as "Hello, World!", is known as a String literal. A number such as 45.2 would be an example of a literal of type double, and -72 would be an example of a literal of type int. Our HelloWorld program contains just a single literal value, the "HelloWorld!" String.

A Java program is a collection of statements. A statement is a segment of code that takes some action in the program. As a program runs, we say it executes statements, meaning it carries out the actions specified by those statements. In our HelloWorld program, statements of various types occur on lines 8, 11, 15, 16, and 17. Notice that all of these lines end with a semicolon. The rule in Java is that statements must end with a semicolon. Forgetting to do so would cause a syntax error.

A declaration statement is a statement that declares a variable of a particular type. In Java, a variable must be declared before it can be used in a program. Failure to do so would cause a syntax error. In its simplest form, a declaration statement begins with the variable’s type, which is followed by the variable’s name, and ends with a semicolon:

Type VariableName ;

A variable’s type is either one of the primitive types we mentioned, such as int, double, or boolean, or for objects, it is the name of the object’s class, such as String or HelloWorld. A variable’s name may be any legal identifier, as defined earlier, although the convention in Java is to begin variable names with a lowercase letter. In our HelloWorld program, an example a simple declaration statement occurs on line 15:

This example declares a variable for an object. The variable’s name is helloworld and its type is HelloWorld, the name of the class that is being defined in our example. To take another example the following statements declare two intvariables, named int1 and int2:

As we noted, an int is one of Java’s primitive types and the word int is a Java keyword.

Without going into too much detail at this point, declaring a variable causes the program to set aside enough memory for the type of data that will be stored in that variable. So in this example, Java would reserve enough space to store an int.

An assignment statement is a statement that stores (assigns) a value in a variable. An assignment statement uses the equal sign (\(=\)) as an assignment operator. In its simplest form, an assignment statement has a variable on the left hand side of the equals sign and some type of value on the right hand side. Like other statements, an assignment statement ends with a semicolon:

VariableName = Value ;

When it executes an assignment statement, Java will first determine what value is given on the right hand side and then assign (store) that value to (in) the variable on the left hand side. Here are some simple examples:

In the first case, the value on the right hand side is the string literal "Hello, World!", which gets stored in greeting. Of course, greeting has to be the right type of container–in this case, a String variable. In the next case, the value on the right hand side is 50. So that is the value that gets stored in num1, assuming that num1 is an int variable. The situation after this assignment is shown in the top drawing in Figure [fig:assign]. In the third case, the value on the right hand side is 25, which is determined by adding 10 and 15. So the value that gets assigned to num2 is 25. After this assignment we have the situation shown in the middle drawing in the figure. Of course, this assumes that num2 is an intvariable. In the last case, the value on the right hand side is 25, the value that we just stored in the variable num2. So, 25 gets stored in num1. This is the bottom drawing in the accompanying figure.

The last of these examples

can be confusing to beginning programmers, so it is worth some additional comment. In this case, there are variables on both the left and right of the assignment operator. But they have very different meaning. The variable on the right is treated as a value. If that variable is storing 25, then that is its value. In fact, whatever occurs on the right hand side of an assignment operator is treated as a value. The variable on the left hand side is treated as a memory location. It is where the value 25 will be stored as a result of executing this statement. The effect of this statement is to copy the value stored in num2 into num1 , as illustrated in Figure [fig:assign2].

Java has many other kinds of statements and we will be learning about these in subsequent examples. The following examples from the HelloWorld program are examples of statements in which a method is called:

We will discuss these kinds of statements in greater detail as we go along. One final type of statement that should be mentioned at this point is the compound statement (or block ), which is a sequence of statements contained within braces (). We see three examples of this in the HelloWorld program. The body of a class definition extends from lines 7 through 19. The body of the greet() method is a block that extends from lines 10 through 12. The body of the main()method is a block that extends from lines 14 to 19.

Expressions and Operators

The manipulation of data in a program is done by using some kind of expression that specifies the action. An expression is Java code that specifies or produces a value in the program. For example, if you want to add two numbers, you would use an arithmetic expression, such as \(num1 + num2\). If you want to compare two numbers, you would use a relation expression such as \(num1 < num2\). As you can see, these and many other expressions in Java involve the use of special symbols called operators . Here we see the addition operator (\(+\)) and the less-than operator (\(<\)). We have already talked about the assignment operator (\(=\)).

Java expressions and operators have a type that depends on the type of data that is being manipulated. For example, when adding two int values, such as \(5 + 10\), the expression itself produces an int result. When comparing two numbers with the less than operator, \(num1 < num2\), the expression itself produces a boolean type, either true or false.

It is important to note that expressions cannot occur on their own. Rather they occur as part of the program’s statements. Here are some additional examples of expressions:

The first of these is an assignment expression. It has a value of 7, because it is assigning 7 to num. The second example is also an assignment expression, but this one has a method call, square(7), on its right hand side. (We can assume that a method named square() has been appropriately defined in the program.) A method call is just another kind of expression. In this case, it has the value 49. Note that an assignment expression can be turned into a stand-alone assignment statement by placing a semicolon after it.

The third expression is an equality expression, which has the value true, assuming that the variable on its left is storing the value 7. It is important to note the difference between the assignment operator (\(=\)) and the equality operator (\(==\)).

What is stored in the variable num after the following two statements are executed?

Write a statement that will declare a variable of type int called num2, and store in it the sum of 711 and 712.

Class Definition

A Java program consists of one or more class definitions. In the HelloWorld example, we are defining the HelloWorldclass, but there are also three predefined classes involved in the program. These are the Object, String, and Systemclasses all of which are defined in the Java class library. Predefined classes, such as these, can be used in any program.

As the HelloWorld program’s comments indicate, a class definition has two parts: a class header and a class body . In general, a class header takes the following form, some parts of which are optional ( opt ): \[\hbox{\it ClassModifiers}_{\hbox{\scriptsize\it opt}}\quad \hbox{\tt class}\quad \hbox{\it ClassName}\quad \hbox{\it Pedigree}_{\hbox{\scriptsize\it opt}}\]

The class header for the HelloWorld class is:

The purpose of the header is to give the class its name (HelloWorld), identify its accessibility (public as opposed to private), and describe where it fits into the Java class hierarchy (as an extension of the Object class). In this case, the header begins with the optional access modifier, public, which declares that this class can be accessed by any other classes. The next part of the declaration identifies the name of the class, HelloWorld. And the last part declares that HelloWorld is a subclass of the Object class. We call this part of the definition the class’s pedigree.

As you recall from Chapter [chapter-intro], the Object class is the top class of the entire Java hierarchy. By declaring that HelloWorld extends Object, we are saying that HelloWorld is a direct subclass of Object. In fact, it is not necessary to declare explicitly that HelloWorld extends Object because that is Java’s default assumption. That is, if you omit the extends clause in the class header, Java will automatically assume that the class is a subclass of Object.

The class’s body, which is enclosed within curly brackets (), contains the declaration and definition of the elements that make up the objects of the class. This is where the object’s attributes and actions are defined.

Declaring an Instance Variable

There are generally two kinds of elements declared and defined in the class body: variables and methods. As we described in Chapter [chapter-intro], an instance variable is a variable that belongs to each object, or instance, of the class. That is, each instance of a class has its own copies of the class’s instance variables. The HelloWorld class has a single instance variable, (greeting), which is declared as follows:

In general, an instance variable declaration has the following syntax, some parts of which are optional:

\[\hbox{\it Modifiers}_{\hbox{\scriptsize\it opt}}\quad \hbox{\it Type}\quad \hbox{\it VariableName}\quad \hbox{\it InitializerExpression}_{\hbox{\scriptsize\it opt}}\]

Thus, a variable declaration begins with optional modifiers. In declaring the greeting variable, we use the access modifier, private, to declare that greeting, which belongs to the HelloWorld class, cannot be directly accessed by other objects. The next part of the declaration is the variable’s type. In this case, the greeting variable is a String, which means that it can store a string object. The type is followed by the name of the variable, in this case (greeting). This is the name that is used to refer to this memory location throughout the class. For example, notice that the variable is referred to on line 11 where it is used in a println() statement.

The last part of the declaration is an optional initializer expression. In this example, we use it to assign an initial value, “Hello, World!,” to the greeting variable.

Defining an Instance Method

Recall that a method is a named section of code that can be called or invoked to carry out an action or operation. In a Java class, the methods correspond to the object’s behaviors or actions. The HelloWorld program has two method definitions: the greet() method and the main() method.

A method definition consists of two parts: the method header and the method body. In general, a method header takes the following form, including some parts which are optional:

\[\hbox{\it Modifiers}_{\hbox{\scriptsize\it opt}}\quad \hbox{\it ReturnType}\quad \hbox{\it MethodName}\quad \hbox{\tt (}\quad \hbox{\it ParameterList}_{\hbox{\scriptsize\it opt}} \hbox{\tt )}\quad\]

As with a variable declaration, a method definition begins with optional modifiers. For example, the definition of the greet() method on line 9 uses the access modifier, public, to declare that this method can be accessed or referred to by other classes. The main() method, whose definition begins on line 13, is a special method, and is explained in the next section.

The next part of the method header is the method’s return type. This is the type of value, if any, that the method returns. Both of the methods in HelloWorld have a return type of void. This means that they don’t return any kind of value. Void methods just execute the sequence of statements given in their bodies. For an example of a method that does return a value, take a look again at the declaration of the getQuestion() method in the Riddle class, which returns a String(Fig. [fig:riddleclass]).

The method’s name follows the method’s return type. This is the name that is used when the method is called. For example, the greet() method is called on line 17.

Following the method’s name is the method’s parameter list. A parameter is a variable that temporarily stores data values that are being passed to the method when the method is called. Some methods, such as the greet() method, do not have parameters, because they are not passed any information. For an example of a method that does have parameters, see the Riddle() constructor, which contains parameters for the riddle’s question and answer (Fig. [fig:riddleclass]).

The last part of method definition is its body, which contains a sequence of executable statements. An executable statement is a Java statement that takes some kind of action when the program is run. For example, the statement in the greet() method,

prints a greeting on the console.

Java Application Programs

The HelloWorld program is an example of a Java application program , or a Java application, for short. An application program is a stand-alone program, “stand-alone” in the sense that it does not depend on any other program, like a Web browser, for its execution. Every Java application program must contain a main() method, which is where the program begins execution when it is run. For a program that contains several classes, it is up to the programmer to decide which class should contain the main() method. We don’t have to worry about that decision for the HelloWorld, because it contains just a single class.

Because of its unique role as the starting point for every Java application program, it is very important that the header for the main method be declared exactly as shown in the HelloWorld class:

It must be declared public so it can be accessed from outside the class that contains it. The static modifier is used to designate main() as a class method. As you might recall from Chapter 0, a class method is a method that is associated directly with the class that contains it rather than with the objects of the class. A class method is not part of the class’s objects. Unlike instance methods, which are invoked through a class’s objects, a class method is called through the class itself. Thus, a class method can be called even before the program has created objects of that class. Because of main()’s special role as the program’s starting point, it is necessary for main() to be a class method because it is called, by the Java runtime system, before the program has created any objects.

The main() method has a void return type, which means it does not return any kind of value. Finally, notice that main()’s parameter list contains a declaration of some kind of String parameter named args . This is actually an array that can be used to pass string arguments to the program when it is started up. We won’t worry about this feature until our chapter on arrays.

Creating and Using Objects

The body of the main() method is where the HelloWorld program creates its one and only object. Recall that when it is run the HelloWorld program just prints the “Hello World!” greeting. As we noted earlier, this action happens in the greet() method. So in order to make this action happen, we need to call the greet() method. However, because the greet() method is an instance method that belongs to a HelloWorld object, we first need to create a HelloWorld instance. This is what happens in the body of the main() method (Fig. [fig:helloworld]).

The main() method contains three statements:

The first statement declares a variable of type HelloWorld, which is then assigned a HelloWorld object. The second statement creates a HelloWorld object. This is done by invoking the HelloWorld() constructor method. Creating an object is called object instantiation because you are creating an instance of the object. Once a HelloWorld instance is created, we can use one of its instance methods to perform some task or operation. Thus, in the third statement, we call the greet() method, which will print “Hello World!” on the console.

If you look back at the HelloWorld program in Figure [fig:helloworld] you won’t find a definition of a constructor method. This is not an error because Java will provide a default constructor if a class does not contain a constructor definition. The default constructor is a trivial constructor method, “trivial” because its body contains no statements. Here is what the default HelloWorld() constructor would look like:

For most of the classes we design, we will design our own constructors, just as we did in the Riddle class (Fig. [fig:riddleclass]). We will use constructors to assign initial values to an object’s instance variables or to perform other kinds of tasks that are needed when an object is created. Because the HelloWorld object doesn’t require any startup tasks, we can make do with the default constructor.

The HelloWorld program illustrates the idea that an object-oriented program is a collection of interacting objects. Although we create just a single HelloWorld object in the main() method, there are two other objects used in the program. One is the greeting, which is a String object consisting of the string “Hello, World!”. The other is the System.out object, which is a special Java system object used for printing.

Java JFrames

Java cann run a program in a JFrame so that the output and interaction occurs in a Window (or Frame). Figure [fig:hellojframe] shows a Java program named HelloWorldSwing. This program does more or less the same thing as

the HelloWorld application—it displays the “Hello, World!” greeting. The difference is that it displays the greeting within a Window rather than directly on the console.

As in the case of the HelloWorld console application program, HelloWorldCanvas consists of a class definition. It contains a single method definition, the paint() method, which contains a single executable statement:

This statement displays the “Hello, World!” message directly in a Window. The drawString() method is one of the many drawing and painting methods defined in the Graphics class. Every Java Canvas comes with its own Graphicsobject, which is referred to here simply as g. Thus, we are using that object’s drawString() method to draw on the window. Don’t worry if this seems a bit mysterious now. We’ll explain it more fully when we take up graphics examples again.

The HelloWorldSwing also contains some elements, such as the import statements, that we did not find in the HelloWorld application. We will now discuss those features.

Java Library Packages

Recall that the HelloWorld application program used two pre-defined classes, the String and the System classes. Both of these classes are basic language classes in Java. The HelloWorldSwing program also uses pre-defined classes, such as JFrame and Graphics. However, these two classes are not part of Java’s basic language classes. To understand the difference between these classes, it will be necessary to talk briefly about how the Java class library is organized.

A package is a collection a inter-related classes in the Java class library. For example, the java.lang package contains classes, such as Object, String, and System, that are central to the Java language. Just about all Java programs use classes in this package. The java.awt package provides classes, such as Button, TextField, and Graphics, that are used in graphical user interfaces (GUIs). The java.net package provides classes used for networking tasks, and the java.iopackage provides classes used for input and output operations.

All Java classes belong to some package, including those that are programmer defined. To assign a class to a package, you would provide a package statement as the first statement in the file that contains the class definition. For example, the files containing the definitions of the classes in the java.lang package all begin with the following statement.

If you omit package statement, as we do for the programs in this book, Java places such classes into an unnamed default package.

Thus, for any Java class, its full name includes the name of the package that contains it. For example, the full name for the System class is java.lang.System and the full name for the String class is java.lang.String. Similarly, the full name for the Graphics class is java.awt.Graphics. In short, the full name for a Java class takes the following form:

\[\hbox{\it package.class}\quad\]

In other words, the full name of any class provides its package name as a prefix.

Of all the packages in the Java library, the java.lang package is the only one whose classes are available by their shorthand names to all Java programs. This means that when a program uses a class from the java.lang package, it can refer to it simply by its class name. For example, in the HelloWorld program we referred directly to the String class rather than to java.lang.String.

The import Statement

The import statement makes Java classes available to programs under their abbreviated names. Any public class in the Java class library is available to a program by its fully qualified name. Thus, if a program was using the Graphics class, it could always refer to it as java.awt.Graphics. However, being able to refer to Graphics by its shorthand name, makes the program a bit shorter and more readable.

The import statement doesn’t actually load classes into the program. It just makes their abbreviated names available. For example, the import statements in HelloWorldSwing allow us to refer to the JFrame, Canvas, and Graphics classes by their abbreviated names (Fig. [fig:hellojframe]).

The import statement takes two possible forms: \[\hbox{\tt import }\quad \hbox{\it package.class}\quad\] \[\hbox{\tt import }\quad \hbox{\it package.*}\quad\\\]

The first form allows a specific class to be known by its abbreviated name. The second form, which uses the asterisk as a wildcard characters (’*’), allows all the classes in the specified package to be known by their short names. The importstatements in HelloWorldSwing are examples of the first form. The following example,

allows all classes in the java.lang package to be referred to by their class names alone. In fact, this particular importstatement is implicit in every Java program.

Qualified Names in Java

In the previous subsections we have seen several examples of names in Java programs that used dot notation . A qualified name is a name that is separated into parts using Java’s dot notation. Examples include package names, such as java.awt, class names, such as javax.swing.JFrame, and even method names, such as helloworld.greet().

Just as in our natural language, the meaning of a name within a Java program depends on the context. For example, the expression helloworld.greet() refers to the greet() method, which belongs to the HelloWorld class. If we were using this expression from within that class, you wouldn’t need to qualify the name in this way. You could just refer to greet() and it would be clear from the context which method you meant.

This is no different than using someone’s first name (“Kim”) when there’s only one Kim around, but using a full name (“Kim Smith”) when the first name alone would be too vague or ambiguous.

One thing that complicates the use of qualified names is that they are used to refer to different kinds of things within a Java program. But this is no different, really, than in our natural language, where names (“George Washington”) can refer to people, bridges, universities, and so on. Here again, just as in our natural language, Java uses the context to understand the meaning of the name. For example, the expression java.lang.System refers to the System class in the java.lang package, whereas the expression System.out.print() refers to a method in the System.out object.

How can you tell these apart? Java can tell them apart because the first one occurs as part of an import statement, so it must be referring to something that belongs to a package. The second expression would only be valid in a context where a method invocation is allowed. You will have to learn a bit more about the Java language before you’ll be able to completely understand these names, but the following provide some naming rules to get you started.

The fact that names are context dependent in this way certainly complicates the task of learning what’s what in a Java program. Part of learning to use Java’s built-in classes is learning where a particular object or method is defined. It is a syntax error if the Java compiler can’t find the object or method that you are referencing.

Browse Course Material

Course info, instructors.

  • Prof. Eric Grimson
  • Prof. John Guttag

Departments

  • Electrical Engineering and Computer Science

As Taught In

  • Programming Languages

Introduction to Computer Science and Programming

Assignments.

facebook

You are leaving MIT OpenCourseWare

Computer Hope

In computer programming , a statement is a single line of code that performs a specific task. For example, the following line of programming code from the Perl programming language is an example of a statement.

In this example statement, a variable ($a) is assigned the value of "3" that is stored as a string . This type of statement is known as an assignment statement because a value is being assigned to a variable.

A complete program has several statements that allow it to do more than assign a variable.

Related information

  • How to create a computer program.

Condition , Conditional statement , Control flow , If statement , Input/output statement , Programming terms

  • Trending Now
  • Foundational Courses
  • Data Science
  • Practice Problem
  • Machine Learning
  • System Design
  • DevOps Tutorial
  • Pre Increment and Post Increment Operator in Programming
  • Unary Operators in Programming
  • What is ASCII - A Complete Guide to Generating ASCII Code
  • Implicit Type Casting
  • Exception Handling in Programming
  • Program to Calculate Income Tax
  • Program to check if a rectangle is a square or not
  • Modulus Operator in Programming
  • Program to convert days to weeks
  • Program to find the area of different shapes | Menu Driven
  • Data Types in Programming
  • Local and Global Variables
  • For loop in Programming
  • Explicit Type Casting
  • Logical AND operator in Programming
  • Variables in Programming
  • Error Handling in Programming
  • While loop in Programming
  • Logical OR operator in Programming

Introduction of Programming Paradigms

Paradigm can also be termed as method to solve some problem or do some task. Programming paradigm is an approach to solve problem using some programming language or also we can say it is a method to solve a problem using tools and techniques that are available to us following some approach. There are lots for programming language that are known but all of them need to follow some strategy when they are implemented and this methodology/strategy is paradigms. Apart from varieties of programming language there are lots of paradigms to fulfill each and every demand. They are discussed below:

assignment statement meaning in computer language

1. Imperative programming paradigm:  It is one of the oldest programming paradigm. It features close relation to machine architecture. It is based on Von Neumann architecture. It works by changing the program state through assignment statements. It performs step by step task by changing state. The main focus is on how to achieve the goal. The paradigm consist of several statements and after execution of all the result is stored.

Advantages:  

  • Very simple to implement
  • It contains loops, variables etc.

Disadvantage:   

  • Complex problem cannot be solved
  • Less efficient and less productive
  • Parallel programming is not possible

Imperative programming is divided into three broad categories: Procedural, OOP and parallel processing. These paradigms are as follows:

  • Procedural programming paradigm –   This paradigm emphasizes on procedure in terms of under lying machine model. There is no difference in between procedural and imperative approach. It has the ability to reuse the code and it was boon at that time when it was in use because of its reusability.

Then comes OOP,

  • Object oriented programming –   The program is written as a collection of classes and object which are meant for communication. The smallest and basic entity is object and all kind of computation is performed on the objects only. More emphasis is on data rather procedure. It can handle almost all kind of real life problems which are today in scenario.
  • Data security
  • Inheritance
  • Code reusability
  • Flexible and abstraction is also present
  • Parallel processing approach –   Parallel processing is the processing of program instructions by dividing them among multiple processors. A parallel processing system posses many numbers of processor with the objective of running a program in less time by dividing them. This approach seems to be like divide and conquer. Examples are NESL (one of the oldest one) and C/C++ also supports because of some library function.

2. Declarative programming paradigm:   It is divided as Logic, Functional, Database. In computer science the declarative programming is a style of building programs that expresses logic of computation without talking about its control flow. It often considers programs as theories of some logic.It may simplify writing parallel programs. The focus is on what needs to be done rather how it should be done basically emphasize on what code is actually doing. It just declares the result we want rather how it has be produced. This is the only difference between imperative (how to do) and declarative (what to do) programming paradigms. Getting into deeper we would see logic, functional and database.

  • Logic programming paradigms –   It can be termed as abstract model of computation. It would solve logical problems like puzzles, series etc. In logic programming we have a knowledge base which we know before and along with the question and knowledge base which is given to machine, it produces result. In normal programming languages, such concept of knowledge base is not available but while using the concept of artificial intelligence, machine learning we have some models like Perception model which is using the same mechanism.  In logical programming the main emphasize is on knowledge base and the problem. The execution of the program is very much like proof of mathematical statement, e.g., Prolog
  • Functional programming paradigms –   The functional programming paradigms has its roots in mathematics and it is language independent. The key principle of this paradigms is the execution of series of mathematical functions. The central model for the abstraction is the function which are meant for some specific computation and not the data structure. Data are loosely coupled to functions.The function hide their implementation. Function can be replaced with their values without changing the meaning of the program. Some of the languages like perl, javascript mostly uses this paradigm.

The next kind of approach is of Database.

  • Database/Data driven programming approach –   This programming methodology is based on data and its movement. Program statements are defined by data rather than hard-coding a series of steps. A database program is the heart of a business information system and provides file creation, data entry, update, query and reporting functions. There are several programming languages that are developed mostly for database application. For example SQL. It is applied to streams of structured data, for filtering, transforming, aggregating (such as computing statistics), or calling other programs. So it has its own wide application.

Please Login to comment...

Similar reads.

  • Object-Oriented-Design
  • Technical Scripter 2018
  • Programming
  • How to Organize Your Digital Files with Cloud Storage and Automation
  • 10 Best Blender Alternatives for 3D Modeling in 2024
  • How to Transfer Photos From iPhone to iPhone
  • What are Tiktok AI Avatars?
  • 30 OOPs Interview Questions and Answers (2024)

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Statement vs Expression – What's the Difference in Programming?

Ogundiran Ayobami

Learning the syntax of a programming language is key if you want to use that language effectively. This is true for both new and experienced developers.

And one of the most important things to pay attention to while learning a programming language is whether the code you're dealing with is a statement or an expression.

It can sometimes be confusing to differentiate between statements and expressions in programming. So this article is meant to simplify the differences so that you can improve your programming skills and become a better developer.

What is an Expression in Programming?

Senior caucasian man holding blank empty banner covering mouth with hand, shocked and afraid for mistake. surprised expression

An expression is any word or group of words or symbols that is a value. In programming, an expression is a value, or anything that executes and ends up being a value.

It is necessary to understand that a value is unique. For example, const , let , 2 , 4 , s , a , true , false , and world are values because each of them is unique in meaning or character.

Let's look at some code as an example:

Judging from the code above, const , price , = , and 500 are expressions because each of them has a definite and unique meaning or value. But if we take all of them together const price = 500 - then we have a statement.

Let's look at another example:

Looking at the code above, you can see an anonymous function is assigned to a variable. Oh, wait! You might know that any function is a statement. Can it also be an expression?

Yes! A "function" and a "class" are both statements and expressions because they can perform actions (do or not do tasks) and still execute to a value.

This brings us to statements – so what are they?

What is a Statement in Programming?

A statement is a group of expressions and/or statements that you design to carry out a task or an action.

Statements are two-sided – that is, they either do tasks or don't do them. Any statement that can return a value is automatically qualified to be used as an expression. That is why a function or class is a statement and also an expression in JavaScript.

If you look at the example of the function under the section on expressions, you can see it is assigned and execute to a value passed to a variable. That is why it is an expression in that case.

Examples of Statements in Programming

Inline statements.

The whole of the code above is a statement because it carries out the task of assigning $2000 to amount . It is safe to say a line of code is a statement because most compilers or interpreters don't execute any standalone expression.

Happy man portraits

Block statements

Look at the below if statement:

The if statement is a statement because it helps us check whether I love you or not. As I have said before, it is two-sided: this code finds out whether "I love you" or not, and that is why it is a statement. Also, it doesn't return any value but it can create side effects.

Here's a loop statement:

In short, any loop is a statement because if it can only do the tasks it is meant to do or not – does loop and doesn't loop. But a loop can't execute to a value in the end. They can only have side effects in JavaScript. Once they can execute to a value in a programming language, then they can also be used as an expression.

For example, you can use forloop and if statement as expressions in Python.

There is also an "IF" expression in Python. That means that something that is a statement in one language can be an expression (or both statement and expression) in another.

Look at the below function statement:

We declare the function add(firstNumber, secondNumber) and it returns a value. The function is called with two arguments as in add(2, 3) by declaration and so it is a statement. If you pay close attention, you will realize that calling the function as a statement is useless since it has no side effect.

Hey, stop! How can we turn it into an expression? Oh yeah, we can do it like this:

Though the function is now an expression the way it is called above, the whole of the code is still a statement.

Check out this class statement:

You can see that we declare the class "Person" and instantiate and assign it to "User" immediately. So, it is used as an expression.

Now, let's use it as a statement:

A class is similar to a function in the sense that it can be declared, assigned, or used as an operand just like a class. So, a class is a statement and/or an expression.

The Main Differences Between an Expression and a Statement in Programming

Expressions can be assigned or used as operands, while statements can only be declared.

Statements create side effects to be useful, while expressions are values or execute to values.

Expressions are unique in meaning, while statements are two-sided in execution. For example, 1 has a certain value while go( ) may be executed or not.

Statements are the whole structure, while expressions are the building blocks. For example, a line or a block of code is a statement.

Why You Should Know the Difference

First of all, understanding the difference between statements and expressions should make learning new programming languages less surprising. If you're used to JavaScript, you may be surprised by Python's ability to assign an if statement as a variable which is not possible in JavaScript.

Second, it makes it easy to use programming paradigms across different programming languages.

For example, a JavaScript "if statement" cannot be used as an expression because it can't execute to a value – it can only create side effects. Yet, you can use the ternary operator if you want to avoid the side effects of using an if statement in JavaScript.

For this reason, you can understand why some programmers avoid if statements by using the ternary operator in JavaScript. It is because they want to avoid side effects .

It also makes your realize why you have to be always careful about the scope of your variables whenever you use a statement. This is true because statements mostly have side effects to be useful, and it is reasonable to understand the scope of your variables and operations. For example,

Hey wait! What would be logged in the console if you ran the code above?

Tell yourself the answer first and then paste the code in the console to confirm. If you you're wrong, you need to learn more about scope and side effects. But if you're right, try to make those functions a bit better to avoid the confusion they may generate.

Knowing the difference also helps you to easily identify non-composable and composable syntaxes (functions, classes, modules, and so on) of a programming language. This makes porting your experience from one programming language to another more interesting and direct.

Wrapping Up

Now that you understand the difference between expressions and statements in programming, and you know why understanding the differences is important, you can identify pieces of code as expressions or statements while coding.

Next time, we'll go even further and help make learning a second programming language easier.

Go and get things done now! See you soon.

I am planning to share a lot about programming tips and tutorials in 2023. If you're struggling to build projects or you want to stay connected with my write-ups and videos, please join my list at YouTooCanCode or subscribe to my YouTube channel at You Too Can Code on YouTube .

Ayobami loves writing history with JavaScript(React) and PHP(Laravel). He has been making programming fun to learn for learners. Check him out on YouTube: https://bit.ly/3usOu3s

If you read this far, thank the author to show them you care. Say Thanks

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

IMAGES

  1. 1.4. Expressions and Assignment Statements

    assignment statement meaning in computer language

  2. PPT

    assignment statement meaning in computer language

  3. What are Assignment Statement: Definition, Assignment Statement Forms

    assignment statement meaning in computer language

  4. PPT

    assignment statement meaning in computer language

  5. PPT

    assignment statement meaning in computer language

  6. PPT

    assignment statement meaning in computer language

VIDEO

  1. L02

  2. C++ Variables, Literals, an Assignment Statements [2]

  3. Java Programming in sinhala Control Statement If Else Statement Part 03

  4. Class 10

  5. 6

  6. Describe Assignment Statement in C language

COMMENTS

  1. Assignment (computer science)

    Assignment (computer science) In computer programming, an assignment statement sets and/or re-sets the value stored in the storage location (s) denoted by a variable name; in other words, it copies a value into the variable. In most imperative programming languages, the assignment statement (or expression) is a fundamental construct.

  2. What are Assignment Statement: Definition, Assignment Statement ...

    An Assignment statement is a statement that is used to set a value to the variable name in a program. Assignment statement allows a variable to hold different types of values during its program lifespan. Another way of understanding an assignment statement is, it stores a value in the memory location which is denoted.

  3. What is an Assignment?

    Assignment: An assignment is a statement in computer programming that is used to set a value to a variable name. The operator used to do assignment is denoted with an equal sign (=). This operand works by assigning the value on the right-hand side of the operand to the operand on the left-hand side. It is possible for the same variable to hold ...

  4. PDF The assignment statement

    The assignment statement. The assignment statement is used to store a value in a variable. As in most programming languages these days, the assignment statement has the form: <variable>= <expression>; For example, once we have an int variable j, we can assign it the value of expression 4 + 6: int j; j= 4+6; As a convention, we always place a ...

  5. The Assignment Statement

    The meaning of the first assignment is computing the sum of the value in Counter and 1, and saves it back to Counter. Since Counter 's current value is zero, Counter + 1 is 1+0 = 1 and hence 1 is saved into Counter. Therefore, the new value of Counter becomes 1 and its original value 0 disappears. The second assignment statement computes the ...

  6. Assignment

    The assignment operator allows us to change the value of a modifiable data object (for beginning programmers this typically means a variable). It is associated with the concept of moving a value into the storage location (again usually a variable). Within most programming languages the symbol used for assignment is the equal symbol.

  7. PDF Resource: Variables, Declarations & Assignment Statements

    That's how assignment works. But in algebra, the equal sign means that the values on both sides are the same. So the way you know computing isn't algebra is that x = x + 1 is meaningless in algebra. No number equals itself plus one. That is a contradiction. So, when you see assignment statements in programming, realize that they mean to ...

  8. CS105: Variables and Assignment Statements

    The assignment operator = is used to associate a variable name with a given value. For example, type the command: a=3.45. in the command line window. This command assigns the value 3.45 to the variable named a. Next, type the command: a. in the command window and hit the enter key. You should see the value contained in the variable a echoed to ...

  9. PDF 1. The Assignment Statement and Types

    Rule 1. Name must be comprised of digits, upper case letters, lower case letters, and the underscore character "_". Rule 2. Must begin with a letter or underscore. A good name for a variable is short but suggestive of its role: Circle_Area.

  10. Variables and Assignment Statements: Assignment Statements

    An assignment statement changes the value that is held in a variable. The program uses an assignment statement. The assignment statement puts the value 123 into the variable. In other words, while the program is executing there will be a 64 bit section of memory that holds the value 123. Remember that the word "execute" is often used to mean "run".

  11. Variables and Assignment Statements

    Definition. An assignment statement is a line of code in which a variable is given a value. An assignment statement has this general form: <variable> = <expression> ... The computer language C was developed in the early 1970s. It was one of the first high-level computer languages and has exerted a great deal of influence on many current ...

  12. 2. Assignment Statements

    Assignment Statements. One of the most common statements (instructions) in C++ is the assignment statement, which has the form: destination = expression ; = is the assignment operator. This statement means that the expression on the right hand side should be evaluated, and the resulting value stored at the desitnation named on the left.

  13. Programming

    Assignment means: "storing a value (of a particular type) under a variable name". Think of each assignment as copying the value of the righthand side of the expression into a "bucket" associated with the left hand side name! Read this as, the variable called "name" is "assigned" the value computed by the expression to the right of the ...

  14. 1.4: Java Language Elements

    An assignment statement is a statement that stores (assigns) a value in a variable. An assignment statement uses the equal sign (\(=\)) as an assignment operator. In its simplest form, an assignment statement has a variable on the left hand side of the equals sign and some type of value on the right hand side.

  15. Different Forms of Assignment Statements in Python

    Multiple- target assignment: x = y = 75. print(x, y) In this form, Python assigns a reference to the same object (the object which is rightmost) to all the target on the left. OUTPUT. 75 75. 7. Augmented assignment : The augmented assignment is a shorthand assignment that combines an expression and an assignment.

  16. Assignment Operators in C

    This operator first adds the current value of the variable on left to the value on the right and then assigns the result to the variable on the left. Example: (a += b) can be written as (a = a + b) If initially value stored in a is 5. Then (a += 6) = 11. 3. "-=" This operator is combination of '-' and '=' operators.

  17. Expression vs. Statement

    Expression vs. Statement. 1. Introduction. This tutorial will review two commonly used terms in Computer Science, namely expressions and statements, along with the differences between them. 2. Expression. An expression usually refers to a piece of code that can be evaluated to a value, and is composed of variables, operators, function calls ...

  18. Assignments

    Assignments. pdf. 98 kB Getting Started: Python and IDLE. file. 193 B shapes. ... Electrical Engineering and Computer Science; As Taught In ... Topics Engineering. Computer Science. Programming Languages; Download Course. Over 2,500 courses & materials Freely sharing knowledge with learners and educators around the world. Learn more

  19. What is a Statement?

    In computer programming, a statement is a single line of code that performs a specific task. For example, the following line of programming code from the Perl programming language is an example of a statement.

  20. Introduction of Programming Paradigms

    Program statements are defined by data rather than hard-coding a series of steps. A database program is the heart of a business information system and provides file creation, data entry, update, query and reporting functions. There are several programming languages that are developed mostly for database application. For example SQL.

  21. Statement vs Expression

    Expressions are unique in meaning, while statements are two-sided in execution. For example, 1 has a certain value while go( ) may be executed or not. Statements are the whole structure, while expressions are the building blocks. For example, a line or a block of code is a statement.

  22. Statement (computer science)

    In computer programming, a statement is a syntactic unit of an imperative programming language that expresses some action to be carried out. A program written in such a language is formed by a sequence of one or more statements. A statement may have internal components (e.g. expressions). Many programming languages (e.g. Ada, Algol 60, C, Java, Pascal) make a distinction between statements and ...