lundi 28 octobre 2019

Why the following code block is giving output "ZZZ(some garbage value)" instead of "ZZ(some garbage value)"

On printing the &a (cout<<&a), compiler is giving output 'Z' but when we print character before printing character address it gives output(cout<<a<<" "<<&a) as 'Z ZZ'. I know that cout treats character address differently i.e on getting an address of character it doesn't print that address instead it prints the contents which are there at that address. Please help me with the concept i am missing here. Here is the code snippet:

#include <iostream>
using namespace std;
int main() {
    char a = 'Z';
    cout<<a<<&a;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire