home > 写経編 > 柴田望洋『明解C言語 入門編』 > 6. 関数 >

ForNext

Only Do What Only You Can Do

053. 自動記憶域期間 と 静的記憶域期間

VBScript

JScript

Perl

更新日 : 2010.10.18
$fx = 0;

sub func
{
    $sx;
    my $ax;
    printf("%3d%3d%3d\n", $ax++, $sx++, $fx++);
}

print " ax sx fx\n";
print "---------\n";

for (1..10)
{
    &func;
}
L:\>perl lesson_06_053.pl
 ax sx fx
---------
  0  0  0
  0  1  1
  0  2  2
  0  3  3
  0  4  4
  0  5  5
  0  6  6
  0  7  7
  0  8  8
  0  9  9

PHP

更新日 : 2010.11.03
<?php
$fx = 0;

function func()
{
    global $fx;
    global $sx;
    $ax;
    printf("%3d%3d%3d\n", $ax++, $sx++, $fx++);
}

print " ax sx fx\n";
print "---------\n";

for ($i = 1; $i <= 10; $i++)
{
    func();
}
?>
L:\>php lesson_06_053.php
 ax sx fx
---------
  0  0  0
  0  1  1
  0  2  2
  0  3  3
  0  4  4
  0  5  5
  0  6  6
  0  7  7
  0  8  8
  0  9  9

Python

Ruby

PowerShell

Scala

F#

C

更新日 : 2010.10.08
#include <stdio.h>

int fx = 0;

void func(void)
{
    static int sx = 0;
    int        ax = 0;
    printf("%3d%3d%3d\n", ax++, sx++, fx++);
}

int main(int argc, char* argv[])
{
    puts(" ax sx fx");
    puts("---------");

    int i;
    for (i = 1; i <= 10; i++)
        func();

    return 0;
}
R:\>lesson053\project1.exe
 ax sx fx
---------
  0  0  0
  0  1  1
  0  2  2
  0  3  3
  0  4  4
  0  5  5
  0  6  6
  0  7  7
  0  8  8
  0  9  9

C++

C++Builder

VC++

C#

Java

Objective-C

D

VB

VB.NET

Delphi

更新日 : 2010.09.24
program Project1;

{$APPTYPE CONSOLE}

uses
    SysUtils;

var
    fx: Integer = 0;
    i:  Integer;

procedure func();
const
    sx: Integer = 0;
var
//  ax: integer = 0; ローカル変数は初期化できません
    ax: Integer;
begin
    writeln(format('%3d%3d%3d', [ax, sx, fx]));
    inc(ax);
    inc(sx);
    inc(fx);
end;

begin
    writeln(' ax sx fx');
    writeln('---------');

    for i := 1 to 10 do
        func;
end.
S:\>lesson053\project1.exe
 ax sx fx
---------
 10  0  0
  9  1  1
  8  2  2
  7  3  3
  6  4  4
  5  5  5
  4  6  6
  3  7  7
  2  8  8
  1  9  9

Ada

PL/SQL

T-SQL

関数型

inserted by FC2 system