There are some doubts related to given program below. Any discussion will be helpful to understand the internals.
#include <iostream>
using namespace std;
int main() {
// your code goes here
char* ptr = new char[11];
ptr = "helloworld";
cout << ptr;
int* ptr1 = new int[2];
//ptr1 = {12, 24};
cout << ptr1;
return 0;
}
- cout << ptr; prints helloworld (prints value); cout << ptr1 prints address not value. Why??
- Since cout << ptr; prints value, How to get address that new char[11] assigns to ptr.
- If ptr = "helloworld"; is allowed. why ptr1 = {12, 24}; is not allowed?