+ 2

CLASS VS STRUCTURE

When we have classes in oop what is the use of structure...? Both have same syntax... And i think same way of coding... And do vote upon what to use class or structure...

29th Jun 2017, 3:56 PM
Anshul Garg
Anshul Garg - avatar
13 Respuestas
+ 4
see a book has page number and author..so in order to have what you say a variable of type book you need integer and string there only structure comes in handy..basically class is used to manipulate and utilise the oops concepts..
29th Jun 2017, 6:07 PM
Joy Das
Joy Das - avatar
+ 6
mention not but I am not sir I am a 3rd year student haha nice to meet you bro :)
29th Jun 2017, 6:10 PM
Joy Das
Joy Das - avatar
+ 5
Um that is for .NET. Structs and classes are essentially the same in C++. You can code OOP in C++ using structs if you want. It's just not the same as a C struct.
29th Jun 2017, 4:46 PM
Karl T.
Karl T. - avatar
+ 5
Well instead of copy/pasting irrelevant info from stackoverflow, you should try to understand what I've said in my post....
29th Jun 2017, 5:06 PM
Karl T.
Karl T. - avatar
+ 5
Besides, NET is a framework used for C#, its not a language in itself.
29th Jun 2017, 5:11 PM
Karl T.
Karl T. - avatar
+ 5
Joy Das, that is true but you can create functions and use inheritance also in structs...only difference is that members are public by default.
29th Jun 2017, 6:21 PM
Karl T.
Karl T. - avatar
+ 4
Java and C++ are NOT ".NET languages". If you look at the poster's tags.
29th Jun 2017, 4:55 PM
Karl T.
Karl T. - avatar
+ 3
https://stackoverflow.com/questions/13049/whats-the-d 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 the variable contains the entire struct, with all its fields. A variable containing a reference type contains a pointer, or a reference to somewhere else in memory where the actual value resides. This has one benefit, to begin with: value types always contains a value reference types can contain a null-reference, meaning that they don't refer to anything at all at the moment Internally, reference types are implemented as pointers, and knowing that, and knowing how variable assignment works, there are other behavioral patterns: copying the contents of a value type variable into another variable, copies the entire contents into the new variable, making the two distinct. In other words, after the copy, changes to one won't affect the other copying the contents of a reference type variable into another variable, copies the reference, which means you now have two references to the same somewhere else storage of the actual data. In other words, after the copy, changing the data in one reference will appear to affect the other as well, but only because you're really just looking at the same data both places When you declare variables or fields, here's how the two types differ: variable: value type lives on the stack, reference type lives on the stack as a pointer to somewhere in heap memory where the actual memory lives (though note Eric Lipperts article series: The Stack Is An Implementation Detail.) class/struct-field: value type lives completely inside the type, reference type lives inside the type as a pointer to somewhere in heap memory where t
29th Jun 2017, 4:01 PM
AgentSmith
+ 2
@joydas sir i am in 2nd year. HBTI... your college?
29th Jun 2017, 6:10 PM
Anshul Garg
Anshul Garg - avatar
+ 2
@anshul UEMK
30th Jun 2017, 3:56 AM
Joy Das
Joy Das - avatar
+ 1
@Karl His questions included .NET languages, it wasn't based solely around C++. Either way, it gives you a perfect idea of the differences between the two.
29th Jun 2017, 4:52 PM
AgentSmith
+ 1
@Karl C# is, if you look at the tags. And again, the answer addresses their question accurately. As well, it'll be best to just improve your answer and actually provide him with information than worry about which languages in his tags are .NET or not.
29th Jun 2017, 4:58 PM
AgentSmith
+ 1
That was kind of thing i was asking... Thankyou @joydas sir
29th Jun 2017, 6:08 PM
Anshul Garg
Anshul Garg - avatar