have been learning about pointers and arrays lately. If I'm not wrong we can implement both char arrays and char pointers to store string type data. But here in the below example when we initialize a string to char array it works, but when we applycin>>subStr
it gives the error.
The following code in C++ gives me SEGMENTATION FAULT (core dumped) Error Message.. The main issue is with applying the input through cin>> I would like to know more about why this happens.
#include<iostream>
using namespace std;
int main(){
char myStr[] = "We are learners";
char *subStr;
cout<<"Enter the substring : ";
cin>>subStr;
cout<<"You entered " <<subStr;
return 0;
}