console outputs smiley face

后端 未结 3 1825
遇见更好的自我
遇见更好的自我 2021-01-26 07:43

I have this code:

#include \"stdafx.h\"
#include 

typedef struct{
    int s1;
    int s2;
    char c1;
    char* arr;
}inner_struc;


int _tmain         


        
3条回答
  •  没有蜡笔的小新
    2021-01-26 07:59

    You are outputing the second element in this array:

    char arr[3] = {1,2,3};
    

    You have assigned it the values 1 2 and 3, but the variable is of type char, so it is being interpreted as ascii. If you look up what character has a value of 2 on an ascii chart, you will see that it is a smily face. So it is indeed doing what you asked it to do.

    http://mathbits.com/MathBits/CompSci/Introduction/ASCIIch.jpg

    What are you expecting the output to be? if you wanted it to be a number, then you will have to add the character representation of that number into the array. ie in stead of 1, 2 or 3 use '1', '2', and '3'

提交回复
热议问题