What's Here?
- Members: 131,954
- Replies: 470,233
- Topics: 72,881
- Snippets: 2,538
- Tutorials: 664
- Total Online: 1,978
- Members: 85
- Guests: 1,893
Who's Online?
|
An example of nested functions in the D programming language.
|
Submitted By: RodgerB
|
|
|
Rating:
|
|
Views: 308 |
Language: Other Languages
|
|
Last Modified: February 20, 2008 |
Instructions:
1) Create a new *.d file.
2) Copy and paste the snippet into the file.
3) Compile and run. |
Snippet
import std.stdio; // writefln
int main(char[][] args)
{
// The integer value we will be using to
// modify with our nested function.
int intValue = 32;
// Declaration of the nested function.
void multiplyByX(int X)
{
intValue *= X;
}
// If we declared a variable after the
// function, it would not be able to
// access it (e.g. Here).
// Call the nested function.
multiplyByX(5);
// writefln is prefered in D, as printf()
// needs to be length delimited or there
// will be problems with variable sizes.
writefln("Value = ", intValue);
// Return successful.
return 0;
}
Copy & Paste
|
|
|
Programming
Web Development
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|