Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
import std.stdio;
ref int greater(ref int first, ref int second) {
return (first > second) ? first : second;
}
void main() {
int a = 1;
int b = 2;
greater(a, b) += 10;
writefln("a: %s, b: %s", a, b);
}
import std.stdio;
int x = 10;
immutable int y = 30;
const int* p;
pure int purefunc(int i,const char* q,immutable int* s) {
//writeln("Simple print"); //cannot call impure function 'writeln'
debug writeln("in foo()"); // ok, impure code allowed in debug statement
// x = i; // error, modifying global state
// i = x; // error, reading mutable global state
// i = *p; // error, reading const global state
i = y; // ok, reading immutable global state
auto myvar = new int; // Can use the new expression:
return i;
}
void main() {
writeln("Value returned from pure function : ",purefunc(x,null,null));
}
import std.stdio;
int main () {
/* local variable definition */
int a = 100;
int b = 200;
switch(a) {
case 100:
writefln("This is part of outer switch", a );
switch(b) {
case 200:
writefln("This is part of inner switch", a );
default:
break;
}
default:
break;
}
writefln("Exact value of a is : %d", a );
writefln("Exact value of b is : %d", b );
return 0;
}
import std.stdio;
int main () {
/* local variable definition */
int a = 100;
int b = 200;
/* check the boolean condition */
if( a == 100 ) {
/* if condition is true then check the following */
if( b == 200 ) {
/* if condition is true then print the following */
writefln("Value of a is 100 and b is 200" );
}
}
writefln("Exact value of a is : %d", a );
writefln("Exact value of b is : %d", b );
return 0;
}