Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

d
variable
communitycreator

Variable declaration in D programming

Chinweuba Elijah Azubuike

What are variables?

Variables are the names of storage locations that store data of different types upon execution of a code block.

What is a variable declaration in D programming?

The variable declaration tells a compiler that a named variable exists with a given data type. This only holds only at the time of code compilation. Variable declaration involves the defining and initializing of a variable.

Example

Let’s look at the code below:

import std.stdio; 
 /* variable definition: */
int w, x; 
int y;

int main () {  
   /* Variable Initialization */ 
   w = 30; 
   x = 40; 
   y = x + w; 
   writeln("Value of y is : ", y);  
   return 0; 
}

Explanation

From the code above, we add the values of two variables:

  • Lines 3 and 4: We define all the variables we use.

  • Lines 12 to 14: We initialize our variables by assigning values to them.

  • Line 15: We print the summation of variable x and variable y.

RELATED TAGS

d
variable
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike
RELATED COURSES

View all Courses

Keep Exploring