+ 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>

3rd Dec 2018, 5:42 PM
Dhruv garg
Dhruv garg - avatar
3 Antworten
+ 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.
3rd Dec 2018, 6:04 PM
John Wells
John Wells - avatar
+ 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.
3rd Dec 2018, 6:08 PM
blACk sh4d0w
blACk sh4d0w - avatar
3rd Dec 2018, 6:14 PM
Dhruv garg
Dhruv garg - avatar