Variable ExamplesYou might have come across the term variable once in your life. Many of you who associated computer programming might be dealing with variables every day. Variables have different meaning and usage criteria for Mathematics and computer programming. In this tutorial, we will briefly learn the various types of the variable and their specific examples. I. Variables in MathematicsA variable is an alphabet or expression that signifies an unidentified number or unidentified value, or unidentified measure. The applications of variables are primarily found in fields of algebraic expression or algebra. For instance, y + 6= 10 is a linear equation where y is a variable, where 6 and 10 are constants. The variable usually represents a quantity that can be altered or fixed according to the mathematical operation performed. When we talk about variables, you will notice mostly x and y are most commonly used, but this is not specific, and one can use any alphabet. In mathematics, we can describe variables with the help of a function Parts of EquationIn Mathematics, Variables are present in some form of equations. The different parts that assist a variable in forming an Equation are as follows:
For instance, in equation, 10y+ 19 = 201,
Operator: An operator is defined as an arithmetic character that helps to execute several operations on the values. The commonly used operators are + (Sum), - (difference), � (multiplication), /(division), etc.). Term: A term is a single expression of an equation. It can be a number or a variable or a number multiplied by a variable. Examples of VariablesThe examples of variables are given as follows:
In the above equation, x and y represents the variables. Constant in MathematicsIn Mathematics, Constants are defined as the values that are fixed and cannot be altered or change further. The concept of Constant is the exact opposite of a Variable. In algebraic equations, the constant is the fixed numbers that define themselves. For instance, in the below equation 10y+20 = 85;
Types of variables in MathematicsIn Mathematics, the variables are further can be categorized into two types, that are as follows:
The detailed description of each variable type is discussed below: 1. Dependent Variables The dependent variable is defined as the variable whose value varies if there are any changes in another variable's condition present in the same algebraic equation. For example, in the below algebraic equation y = 4x + 3. You will notice that the value of the 'y' variable is dependent on the variations in the value of 'x'.
2. Independent Variables In a mathematic algebraic equation, a variable is defined as an independent variable if values are independent, if there occur any changes in the equation, or to any other variable present in the same equation. For example: if an equation carries x and y as two variables where the value of y is connected with the value of our second variable x, in that case, 'x' value acts as a function variable y value, and thus it is called an independent variable. For Instance: In the below equation y = x+7,
II. Variables in ComputersIn a computer programming language, Variables are a standard container used by language editors to hold information that could be further used throughout a computer program. It is also a process through which you can label your data and its type with a specific name so that other programmers can easily understand the programs. Variables are nothing more than a name you provide to computer memory locations, at which you have stored the information of your program. For instance, you have two integer data values, i.e., 2 and 3, and you frequently want to use these two values within your computer program. To save time and memory, the best option is to store these two values in two variables in computer memory so you can use them anytime. Now, let's see how you will do it. Here are the following three simple steps -
Creating variablesDifferent programming languages have different formats and syntax for creating a variable. For instance, in a programming language like C, creating a variable is also known as declaring variables. Let's see how we can create a variable in C: In the above program, you can see we have created two variables and have named them x and y. These variables are of integer data type as we have specified them using int data type because they want to store integer values in those two variables. Likewise, we can create variables of different data types such as byte, long, float, boolean, char. For example ? Listed below are the key points about variables that you need to keep in mind -
Every programming language has its own rules and syntax to define and create its variable. Let's go further to learn in detail the examples of the store and access the variables. We will also cover the syntax and rules of variable creation commonly used in various programming languages. Store Values in VariablesEarlier, we have covered the process of creating a variable. Let's see how we can assign values to those variables - In the above program, you can see two statements wherein we are storing integer values to our two created variables, i.e., we are storing 40 in x and 50 in y. The process of storing values is approximately the same in all the programming languages where the name of the variables are kept on the left side of the equal sign (=) and the data that you want to store is kept on the right-hand side. Access stored values in variablesIf we don't access the variables in our programs we have created and later have assigned those values, their existence in the program is a waste. Therefore, we will learn how to access the stored value in variables. In the above programs, we have already created two variables named x and y and have stored two values, 40 and 50, respectively. Next, we will access both the values and print the values stored in these two variables. In the below example, we have written a program in C to print the values of the two variables ? Code: Output Variable x = 40 Variable y = 50 Example of Variables in JavaYou can refer to the program given below for creating any variable in the Java programming language. In this code, we have declared two variables, x, and y, with integer data types. Later we have assigned them integer values of 40 and 50, respectively. At last, we have used the 'println' command to print the values of both the two in different ways: Code: Output Variable x = 40 Variable y = 50 Variable x = 40 and Variable y = 50 Example of Variables in PythonYou can refer to the program given below for creating any variable in the Python programming language. In this code, we have created two variables, x, and y, and simultaneously have assigned them values of 40 and 50, respectively. As in the Python programming language, it is not mandatory to specify the data type initially when you are creating a variable. Code: Output: Variable x = 40 Variable y = 50 Variable x = 40 and Variable y = 50 Example of Variable in CYou can refer to the program given below for creating any variable in the C programming language. In this code, we have created two variables, x and y, and simultaneously have assigned them values of 40 and 50, respectively. Code: Output Variable x = 40 and Variable y = 50 Next TopicSequelize |