N
Nick McCamy
I have a question related to allocating on the stack.
In this program below, are my following assumptions true?
- variable a is allocated on the heap since it's static
- variable b is allocated on the stack since it's a value type variable
- variable d is allocated on the stack since it's a value type variable
Where does variable "c" get allocated? It's a value type, but not foundwithin a method.
using System;
namespace MyTest
{
class Class1
{
static int a = 0; // Allocated on the heap.
static void Main(string[] args)
{
int b = 0; // Allocated on the stack.
b = a;
}
}
class Class2
{
int c = 5; // Allocated where?
public int Test(int X)
{
int d = 1; // Allocated on the stack.
return d * X * c;
}
}
}
-Nick McCamy
In this program below, are my following assumptions true?
- variable a is allocated on the heap since it's static
- variable b is allocated on the stack since it's a value type variable
- variable d is allocated on the stack since it's a value type variable
Where does variable "c" get allocated? It's a value type, but not foundwithin a method.
using System;
namespace MyTest
{
class Class1
{
static int a = 0; // Allocated on the heap.
static void Main(string[] args)
{
int b = 0; // Allocated on the stack.
b = a;
}
}
class Class2
{
int c = 5; // Allocated where?
public int Test(int X)
{
int d = 1; // Allocated on the stack.
return d * X * c;
}
}
}
-Nick McCamy