Wednesday - March 13, 2024
#C, C++ and C# #Blog #C Program #Computer Science

What is Variable in c

variable

Variable means an entity whose value seat varies (i.e., change) during the specific execution of a program. A perfectly speaking variable is a named memory location.” yes, the variable is nothing but another name given to memory location. We can use variables to hold any type of data.

Variable declaration

Q) explain the variable declaration.

Q) write the syntax for the declaration of the variable.

  • The declaration means telling the compiler about the name and type of the data hold by the variable, that we want to use in our program. The declaration refers to the process of informing the compiler about the variable used in the program. Before using any variable the variable needs to be declared.

Following is the general form of the declaration of variable:

  • data_type variable_name;

Here,

  • data_type – Type of the data hold by the variable.
  • variable_name – Name of the variable. It can be any valid identifier.

For example:

int a;

  • This statement is called a variable declaration. The statement tells the compiler that “a” is the name of the variable and its data type as int(integer) i.e. it can contain any integer value (-32768 to +32767)

float f;

  • Here, f s the variable of type float.
variables science, variables in research, variables in programming, variables in java, variables in math, types of variables, variables in c, variables in python, types of variables in math, variable computer science, variables in research wikipedia, variable, variable and constant, factor coefficient, javascript variable types, declare variable in html, javascript declare keyword, var java, declare variable java, javascript calculation functions, what is a variable in programming, what is a variable in python, how to pronounce variable, what is a variable in math, every variable has the following attributes,

Variable initialization

Q) explain the initialization of a variable.

Q)write the syntax for the initialization of a variable.

  • Assigning the to variable at the time of creation or declaration is called variable initialization or simply initialization.
  • Initialization provides the value to the variable. if the variable is not initialized, then it will contain unpredictable or non-useful(garbage) values.

Following is the form for the initialization of the variable:

  • data_type variable_name= value;

Here,

  • data_type  – Type of the data hold by the variable.
  • variable_name  – Name of the variable. it can be any valid identifier.
  • Value – The initial value that we want in a variable.

For example:

int i = 10;

  • The above statement is called initialization. This statement declares ‘i’ as the int (integer) variable and will be assigned the value ’10’

Float pi = 3.1415;

  • The above statement will create a variable called “pi” of type float with “3.1415” as the initial value.

The rule for constructing variable names

Q) write the rules for constructing for constructors.

  • Some variable name is any combination of 1 to 31 alphabets, digits or underscores. Any compilers allow variable names whose distance could be up to 247 characters. still, it would be safer to stick to the rule of 31 characters.
  1. A variable name can contain any alphabet, digit or underscore.
  2. The first characters in the variable name must be an alphabet or underscore/
  3. A variable name may contain a maximum of 31 characters.
  4. No commas or blanks are allowed within a variable name.
  5. No special symbol other than an underscore ( as in gross_sal) can be used in a variable name.

.