Code/Study
[C/C++ vs C#] sizeof
Hide Code
2008. 7. 16. 20:18
< C/C++ >
sizeof(variable) 가능
< C# >
sizeof(variable) 불가능
sizeof(variable) 가능
#include <iostream>
using namespace std;
void main()
{
int i = 0;
cout << sizeof(i) << endl; // valid
cout << sizeof(int) << endl; // valid
}
using namespace std;
void main()
{
int i = 0;
cout << sizeof(i) << endl; // valid
cout << sizeof(int) << endl; // valid
}
< C# >
sizeof(variable) 불가능
using System;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
int i = 0;
Console.WriteLine(sizeof(i)); // compile time error
Console.WriteLine(sizeof(int)); // valid
}
}
}
namespace Sample
{
class Program
{
static void Main(string[] args)
{
int i = 0;
Console.WriteLine(sizeof(i)); // compile time error
Console.WriteLine(sizeof(int)); // valid
}
}
}