#include<bits/stdc++.h>
using namespace std;
typedef struct trie
{
int arr[26];
bool isleaf;
trie(int isleaf)
{
this->isleaf=9;
cout<<isleaf<<endl;
isleaf=false;
cout<<isleaf<<endl;
cout<<this->isleaf<<endl;
}
}* tr;
//void inser(s)
int main()
{
tr k=new trie(3);
cout<<k->isleaf;
}
Works Fine and outputs 3 0 1 1
But in
#include<bits/stdc++.h>
using namespace std;
typedef struct trie
{
int arr[26];
bool isleaf;
trie(int isleaf)
{
cout<<isleaf<<endl;
isleaf=false;
cout<<isleaf<<endl;
cout<<this->isleaf<<endl;
}
}* tr;
//void inser(s)
int main()
{
tr k=new trie(3);
cout<<k->isleaf;
}
I get 3 0 68 68
I understand that it is uninitialized but still why 68?
If use a normal bool either in global or inside function and print it without initializing i get 0,then why not here?
And can somebody also point out some good source to clear doubts about such variable declarations , public and private concepts , and OOPS, difference between structs and classes etc.
Aucun commentaire:
Enregistrer un commentaire