Array Comprehension Problem

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>

using namespace std;

int main()

{

    char samplearray[] = {'A','B','S'};

    int n = samplearray[0];

    cout << "The sample array is =  " << samplearray[0] << " " << n ;

    return 0;

} 
Last edited on
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/
Last edited on
> How do I get 65 from the output

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).

Then we print out the integer value (in) n.
Try changing [0] to [1] in L13 and see what is then displayed. Then relate the 65 and this output to the contents of samplearray...
Topic archived. No new replies allowed.