Code Snippets

  

Other Languages Source Code


Welcome to Dream.In.Code
Getting Help is Easy!

Join 131,954 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,978 people online right now. Registration is fast and FREE... Join Now!





D: Nested Functions

An example of nested functions in the D programming language.

Submitted By: RodgerB
Actions:
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


  1. import std.stdio; // writefln
  2.  
  3. int main(char[][] args)
  4. {
  5.     // The integer value we will be using to
  6.     // modify with our nested function.
  7.     int intValue = 32;
  8.    
  9.     // Declaration of the nested function.
  10.     void multiplyByX(int X)
  11.     {
  12.         intValue *= X;
  13.     }
  14.    
  15.     // If we declared a variable after the
  16.     // function, it would not be able to
  17.     // access it (e.g. Here).
  18.    
  19.     // Call the nested function.
  20.     multiplyByX(5);
  21.    
  22.     // writefln is prefered in D, as printf()
  23.     // needs to be length delimited or there
  24.     // will be problems with variable sizes.
  25.     writefln("Value = ", intValue);
  26.    
  27.     // Return successful.
  28.     return 0;
  29. }

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month