Well, this code was taken from a practice exam for a programming thing that i’m very under qualified for, but i’d still like to know the reason behind the output for this.
#include <iostream>
using namespace std;
int main(){
char g = 'X', t = '1', *k_ = &t;
g = 'y';
cout << *k_ << *k_ << endl;
g = 'Y';
cout << *k_;
k_ = &g;
t = 'Z';
cout << *k_ << *k_ << *k_ << endl;
return 0;
}
I don’t understand why the output for the last cout is 1YYY if there are only three k_ pointers, and there’s that 1 that’s bothering me too.
1 Answer