Using NULL in C++?

In C++ NULL expands to 0 or 0L. See this quote from Stroustrup’s FAQ: Should I use NULL or 0? In C++, the definition of NULL is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0. Another problem with NULL is that people sometimes mistakenly believe that … Read more

What is a Memory Heap?

Presumably you mean heap from a memory allocation point of view, not from a data structure point of view (the term has multiple meanings). A very simple explanation is that the heap is the portion of memory where dynamically allocated memory resides (i.e. memory allocated via malloc). Memory allocated from the heap will remain allocated … Read more

What is a char*?

This is a char: It can only hold one character! This is a C-string: It can hold multiple characters. Another way to write the above is: The 0 at the end is called the NUL terminator. It denotes the end of a C-string. A char* stores the starting memory location of a C-string.1 For example, … Read more

how to use math.pi in java

I am having problems converting this formula V = 4/3 π r^3. I used Math.PI and Math.pow, but I get this error: ‘;’ expected Also, the diameter variable doesn’t work. Is there an error there?

When to use virtual destructors?

Virtual destructors are useful when you might potentially delete an instance of a derived class through a pointer to base class: Here, you’ll notice that I didn’t declare Base’s destructor to be virtual. Now, let’s have a look at the following snippet: Since Base’s destructor is not virtual and b is a Base* pointing to … Read more

Difference between Inheritance and Composition

They are absolutely different. Inheritance is an “is-a” relationship. Composition is a “has-a”. You do composition by having an instance of another class C as a field of your class, instead of extending C. A good example where composition would’ve been a lot better than inheritance is java.util.Stack, which currently extends java.util.Vector. This is now … Read more

TypeError: unhashable type: ‘numpy.ndarray’

Your variable energies probably has the wrong shape: And that’s what happens if you read columnar data using your approach: Probably you can simply use instead. (P.S. Your code looks like it’s undecided about whether it’s data or elementdata. I’ve assumed it’s simply a typo.)