learnC | learning c language | Machine Learning library
kandi X-RAY | learnC Summary
kandi X-RAY | learnC Summary
learning c language
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of learnC
learnC Key Features
learnC Examples and Code Snippets
Community Discussions
Trending Discussions on learnC
QUESTION
From the tutorial at learnc, I am experimenting with some really basic stuff on pointers and unions. In the code below I create a struct operator
with an anonymous union
consisting of a float
, double
, and int
. Since double
is the biggest one at eight bytes, I expect to see my int
have eight bytes, which it does. However, they are not the same bytes as the double!
ANSWER
Answered 2018-Nov-24 at 21:25Shouldn't
&(op.intNum)
==&(op.doubleNum)
==&(op.floatNum)
?
Yes, they should, and they are.
In order to print an address, use %p
as the format specifier, and cast it to void*
. Read more in How to print variable addresses in C?
QUESTION
this is my code:
...ANSWER
Answered 2017-Nov-15 at 06:18Your class is not following the Rule of Three because it is missing a proper copy constructor.
String str2 = str1;
is just syntax sugar for String str2(str1);
, so it uses the copy constructor, not your operator=
(which has a memory leak, BTW).
Since you did not provide a copy constructor, the compiler provided one for you, but it does not make a deep copy of the char*
data. It just copies the pointer itself, which causes the behaviors you are seeing.
A proper implementation would look more like this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install learnC
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page