D Programming – Variables

Hi there, I recently enjoyed learning some programming languages which are new to me. I came across with the D Programming Language. I have already put up an article on the codes on the basic console output in D located here: https://arjunaraneta.wordpress.com/2014/09/27/d-basic-output/

You can think of variables as an address in your memory that contains data that you’ll need and use. The syntax for using variables in python in very straightforward.

Here is a basic example of declaring a variable named x with a value of 10. After declaring and assigning a value, the program will output the value of x.

import std.stdio;

int main(){
int x = 10;
writeln("x = ", x);

  return 0;
}

The output should be:

x = 10

On the next example below, I declared two variables named x and y. I assigned a value for each of the variables. After assigning the values, I created another variable named z assigned the sum of x and y. The program will output the result after the addition.

import std.stdio;

int main(){
	int x = 10, y = 5;
	writeln("x + y = ", x + y);
	
	return 0;
}

The output should be:

x + y = 10

Thank you for your time 🙂
Please leave a comment below.
Be free to ask me questions.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s