-2
#include <iostream>
using namespace std;

int main() {

    
    for(int i = 0; i < 10; i++) {
        //print a char including two spaces
       cout<<'  '<<endl;
        //output shows me 8224 
    }
    system("pause");
    return 0;
}

Here is the screenshot of the output

Why does it show me 8224?

KMING
  • 11
  • 5
  • 5
    That won't compile, much less run and print anything. – molbdnilo Sep 01 '21 at 08:54
  • 2
    `char * p` is not a character. It is a pointer to a character – 463035818_is_not_an_ai Sep 01 '21 at 08:57
  • The value of a multi-character character literal is implementation-dependent. Don't use them without consulting the documentation for your compiler. – molbdnilo Sep 01 '21 at 08:58
  • Why output shows me integer value when i print a char including two spaces? – KMING Sep 01 '21 at 09:01
  • 1
    your code **does not compile** https://godbolt.org/z/oc4n8Mv3G – bolov Sep 01 '21 at 09:04
  • You're not printing a `char`, you're printing first a `char*`, and then a `char**` reinterpreted as a `void*`. If you manage to compile it (no compiler will accept it unless you explicitly disable the initial, useful, type error) the first has undefined behaviour, and the second is the location of `p`, not its value. – molbdnilo Sep 01 '21 at 09:07

1 Answers1

0

You're printing a pointer, not the character. char *p is a pointer to a character, and when you print pointers, they look like integers.

The problem is not ' ', although that is a problem, because single quotes expect only one character. Double quotes are used for string literals, which can be stored in a char * pointer.

fortytoo
  • 452
  • 2
  • 11