I have problem initializing array in C++14.
int *arr={1,2,3,4}; // Works in C but does not work in C++
I can't understand the error message it shows
prog.cpp: In function 'int main()':
prog.cpp:6:26: error: scalar object 'arr' requires one element in initializer
int *arr = {1, 22, 5, 20}; //NOT WORKING IN C++
What is the exact meaning of initializer in the error message?
Link of code of C++ which is not working http://ideone.com/684V5t
Link of Same code in C which works http://ideone.com/RAL3te
If anyone can explain why this is happening it would be nice. Thank you.
warning: initialization makes pointer from integer without a cast [enabled by default] int *arr={1,2,3,4};. And this right. You can't put a integer-array initialisation on a int pointer.int *arr = (int[]){1, 2, 3, 4}will work in C, but not in C++. Without proper tagging, I don't know if that's an answer.