Skip to main content Link Search Menu Expand Document (external link)

Struct vs Class Output quiz

Question

What is the cause of the difference between the outputs in the previous struct-class example?

There is a bug in the struct implementation

This comes to the fundamenta difference between classes and structs. Structs are passed by value to functions, meaning that if we pass a struct to a function a copy of it will be created and used, and the actual struct will be unmodified

Structs are passed to functions by value, classes are passed by reference

Correct

The struct was not correctly instantiated, so the default int value was printed

This comes to the fundamenta difference between classes and structs. Structs are passed by value to functions, meaning that if we pass a struct to a function a copy of it will be created and used, and the actual struct will be unmodified

Classes don’t have a deterministic behavior in the given example

This comes to the fundamenta difference between classes and structs. Structs are passed by value to functions, meaning that if we pass a struct to a function a copy of it will be created and used, and the actual struct will be unmodified