Hello. I'm currently studying array right now and I have a question regarding the code below. How do I get 65 from the output, The sample array is A = 65? Can someone explain it to me? Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int main()
{
char samplearray[] = {'A','B','S'};
int n = samplearray[0];
cout << "The sample array is = " << samplearray[0] << " " << n ;
return 0;
}
The ASCII value of 'A' is 65, and ASCII is the representation that (most) modern computers follow for the lower 7 bits of chars. https://www.asciitable.com/
When we do: int n = samplearray[0];
the char value at samplearray[0] is implicitly converted to int and the resultant int value is used
to initialise n (the type which is int).