+ 2
can someone explain output of my code?
It is a simple c++ program of char int and array which i am having trouble understanding. when i output char array i get string and when i output int array i get memory address. https://code.sololearn.com/cFRtyV4IfXn8/?ref=app output : abcd abc <some memory address>
3 Réponses
+ 3
There is no difference between character array and string. Though, since you didn't put a '\0' in your array, you might end up getting characters you didn't expect as the string output goes until it finds that null. C++ doesn't know how to handle arrays or structures for output (except character arrays) so displays the address.
+ 10
It's because intarr is pointing to the first memory address of the array. If you want to print the value of the first index then you need to dereference it by using * operator.
i.e *intarr, it will print the value at first memory address of the array.
Secondly, integer arrays cannot be printed completely like this, you need to make a loop and dereference every index of array and print it.
+ 3
thanks John Wells and nAutAxH AhmAd