Array Problem

Hi Guys I Have Problem


int main(int argc, char** argv)
{
char array[8];
int i;
cin >> array;
i = array[0] + array[1];
cout << i;
return 0;
}

1 + 6 = 103 ???????

How Fix It ? Please Help Me
Could you go into more detail about what exactly is happening? Currently you are adding to uninitialized values, so you could get anything. Also, reading into array directly like that is a recipe for disaster as array is meant to be the memory address of the start of the array, not its values or anything like that.
Last edited on
the type of array is char
‘1’ ASCLL is 49
‘6’ ASCLL is 54
49 + 54 = 103;
Topic archived. No new replies allowed.