What’s the difference between struct and class in .NET?

In .NET, there are two categories of types, reference types and value types. Structs are value types and classes are reference types. The general difference is that a reference type lives on the heap, and a value type lives inline, that is, wherever it is your variable or field is defined. A variable containing a value type contains the entire value type value. For a struct, that means that … Read more

Difference between a Structure and a Union

With a union, you’re only supposed to use one of the elements, because they’re all stored at the same spot. This makes it useful when you want to store something that could be one of several types. A struct, on the other hand, has a separate memory location for each of its elements and they … Read more

Map like structure in C: use int and struct to determine a value

You’ll probably have to make your own structure. The C Programming Language by Kernighan and Ritchie has an example of making an associate map in c, and what I’ll detail below is based on what I remember from that. Basically you’ll need a struct Map that contains struct Key and struct Value. struct Key contains elements that determine the value (in your case 2 … Read more

Error: “Cannot modify the return value” c#

This is because Point is a value type (struct). Because of this, when you access the Origin property you’re accessing a copy of the value held by the class, not the value itself as you would with a reference type (class), so if you set the X property on it then you’re setting the property on the copy and then discarding it, leaving … Read more

“error: assignment to expression with array type error” when I assign a struct field (C)

You are facing issue in because, in the LHS, you’re using an array type, which is not assignable. To elaborate, from C11, chapter §6.5.16 assignment operator shall have a modifiable lvalue as its left operand. and, regarding the modifiable lvalue, from chapter §6.3.2.1 A modifiable lvalue is an lvalue that does not have array type, […] You need to use strcpy() to copy … Read more

C++ struct constructor

will try to initialise the array by calling a default constructor for node. You could either provide a default constructor or, rather verbosely, initialise all 100 elements explicitly or, since you’re using C++, use std::vector instead, appending to it (using push_back) at runtime