Allocate memory in stack using stackalloc keyword

Sourav.Kayal
Posted by Sourav.Kayal under C# category on | Points: 40 | Views : 790
using System;
class Test
{
public static unsafe void Main()
{
int* fib = stackalloc int[100];
int* p = fib;
*p++ = *p++ = 1;
for (int i=2; i<100; ++i, ++p)
*p = p[-1] + p[-2];
for (int i=0; i<10; ++i)
Console.WriteLine (fib[i]);
}
}

Comments or Responses

Login to post response