its been a while since i've done C++ and i am trying to brush up on it, recently i been using python and java, thus a refresher in pointers was needed.
#include <iostream>
using namespace std;
int main()
{
char *s=new char;
cin >>s;
cout <<s<<endl;
delete s;
s=0;
return 0;
}
when i try to do this i understand that i have a char of size 1 Bytes and when i type in something it is stored; and i can print it out. but if i try a large input it overflows, i understand that the size is limited.
now i tried this:
#include <iostream>
using namespace std;
int main()
{
char *s=new char;
cin >>*s;
cout <<s<<endl;
delete s;
s=0;
return 0;
}
only the first letter of what i type is stored, i first through *s is same as s[0], but even if so, it should store everything in s[0].
i am not so sure how to understand this.
Also i tried this:
char *s=new char [2];
cin>>s; // i enter lets say "hello"
cout<<s[3]; // this prints out "l";
what i don't understand is when i said new char [2], what did i exactly do, did i allocate two chars?,