As said in video we should not assign pointer of one datatype to address of a variable of other data types, in case pointer of type char is assigned address of int variable than it should read only one byte of data that is in case of 14 it will just output either 1 or 4 only but on doing the same I am getting compilation error , which I should get, from my prior knowledge
code:
#include
using namespace std;
int main() {
int c = 1;
int b = 12;
int d = 123;
int a = 1234;
char * p = &a;
char *q= &b;
char *r = &c;
char *s = &d;
cout<<*p<<endl;
cout<<*q<<endl;
cout<<*r<<endl;
cout<<*s<<endl;
// cout<<"Sum of x+y = " << z;
return 0;
}
output: compilation error:
I am unable to understand this concept please make me understand this.