using namespace std;

struct node
    int info;
    node *left,*right;

int main()
    struct node *root;
    //root = (struct node*)malloc(sizeof(struct node));
    if(root==NULL) //cout<<root->info;
    cout<<root->info<< " "<<root->left<<" "<<root->right<<"\n";
    return 0;


why it is giving an error?

are you sure you posted in the right forum, the code is in C++ yet this is the C forum and you forgot to post the error messages
Now in a glance, 1 error I see is you should initialize the following variables inside the structure as follows

struct node *left; 
struct node *right

This is also incorrect:

> if(root==NULL) //cout<<root->info;
> cout<<root->info<< " "<<root->left<<" "<<root->right<<"\n";

You are trying to access the info member of root, which is NULL (due to your if statement); this will cause the program to crash.

It is best practice to always wrap statements in curly brackets to prevent unwanted behavior.

This question has already been answered. Start a new discussion instead.