hi Sup Forums, I have a final exam tomorrow for my Into C++ class and I'm going over the practice exam my professor gave out. One of the questions asks what the output of the code in the image is, but when I try to test it out, it says "a value of type "double *" cannot be assigned to an entity of type "double"".
Did my teacher mess this up? Is it a trick question? Can I fix something in the code so that I can see the intended result?
first post on Sup Forums I'll try and post the code. int main () { double *p,*q; double i=2.3, k =4.3; p=new double[2]; *p=i; q=p; cout
Jace Miller
"p[1] = &i" is the culprit (incompatible types). You should see a result (not necessarily that which is intended) by replacing it with "p[1] = (double)&i" (casting the double* to a double)
Oliver Lopez
I attempted to do that and it still says it's an invalid type conversion.
also tried to do static_cast(&i);
Brandon Bailey
Piggy backing for my own question; I have a major assignment due soon in which we have to parse an entire (oxford) dictionary file into an array where every word and its definition are a separate object in order to qucik search the word. Any idea on where to start?
Asher Baker
Your teacher should rethink his approach. Ugly pointer manipulation and naked new/delete is not something you show on the first lesson. The whole community is trying to move away from that...
Gavin Kelly
Just buffer it senpai, you dont want segfaults
Jack Hall
It's so confusing. This is her first semester teaching here. she's from some middle eastern country. I don't understand pointers at all no matter how hard I try and these kinds of quiz questions just mess me up even more.
Kevin Watson
Did they specifically say "an array"? Because when you hear "dictionary" or "key/value pair" you should think "map" or any other associative container.
With an array you'd need to store std::pair and sort/search with a custom compare function which only looks at the first element of each pair. It's doable but completely retarded compared to using std::map.
Adrian Wilson
>p=new double[2]; >p[1] = &i; wew lad you're trying to store a reference (unsigned 32/64bit int) inside a double the reference seems to get converted to a double* which explains the error