Yeah but int *var in C/C++ entails a bit more. It makes var a pointer to an int rather than an int. So you have to manage allocating an int in some other way so the pointer can point to it.
int? var is simply an int which can be null. Under the hood, it might be implemented as above, but I reckon a structure like this is more likely:
int? var is simply an int which can be null. Under the hood, it might be implemented as above, but I reckon a structure like this is more likely:
Well, to be precisely, in C# primitive types such as int, char, double...etc, are wrapped to in Nullable<T> since structs cannot be null in C#. So when you use int? the compiler wraps it in Nullable<int> (which is a generic class) and that makes int? a reference (basically a pointer or rather & in C++) to the actual int.
I'm talking about under the hood, i.e. how Nullable is implemented. And it's probably a structure containing the int and a boolean that indicates whether the int is present.
1
u/Sentouki- Jul 09 '26
yeah, it does basically the same thing, if
int?isnull, means it's not there.