Why the answer is -47 ?
I have written a simple code beacuse i have two strings, one is hard coded and the sum of whose adjacent membrs is to be stored in the other string.but the answer of first two indexes of string 1 is different as following:
while the following code gives 1, why?
The third code gives -47....
#include<iostream.h> #include<conio.h> #include<string.h> int main() { char string1[]="011100011"; char string2[9]; cout<<string1; cout<<endl; string2[0]=(string1[0]-'0'+string1[1]-'0'); cout<<endl; cout<<string2[0]; }This code gives a symile face instead of 1.
while the following code gives 1, why?
#include<iostream.h> #include<conio.h> #include<string.h> int main() { char string1[]="011100011"; char string2[9]; cout<<string1; cout<<endl; string2[0]=(string1[0]+string1[1]-'0'); cout<<endl; cout<<string2[0]-'0'; }The problem can be solved by 2nd code but what is the true logic behind, can u explain........???
The third code gives -47....
#include<iostream.h> #include<conio.h> #include<string.h> int main() { char string1[]="011100011"; char string2[9]; cout<<string1; cout<<endl; string2[0]=(string1[0]-'0'+string1[1]-'0'); cout<<endl; cout<<string2[0]-'0'; }???
0