What is wrong with this code:
Where the integers and amount are initialised:Code:integers = malloc(amount * sizeof(int));
Code:int *integers; int amount = 3;
What is wrong with this code:
Where the integers and amount are initialised:Code:integers = malloc(amount * sizeof(int));
Code:int *integers; int amount = 3;
besides not free()'ing the memory, i cant see anything wrong with it. since you are asking what is wrong, you must be having a problem with it. so what is the problem? either that or this is a direct homework question.
sorry, i was compiling it as C code, not C++. for C code using gcc and options "-Wall -pedantic -std=c99" gave no warning or errors. but twomers gave a hint to how to solve the error for C++.
Thanks! twomers
Whilst a cast will remove the compiler error, the right thing is to use "new", as suggested in post #2 by twomers.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.