I am trying to create a binary search tree and i'm tackling a problem where when i'm trying to add a value in a struct parameter, it immediately gives an exception write access violation. i have two structs , one is a pointer to a BST which contain a Student Node pointer, and a Student Node struct which contain some variables(ID,grades,...), left, right and a parent pointer this are the structs:
typedef struct StudentNode {
    int ID;    //node key
    int MidtermGrade;
    int ExamGrade;
    struct StudentNode* left;
    struct StudentNode* right;
    struct StudentNode* parent;
} StudentNode;
typedef struct BST {
    struct StudentNode* root;
} BST;
this are the functions that i made to create a BST and a new student node
BST* CreateBST() {
    int id;
    BST* tree = (BST*)malloc(sizeof(struct BST));
    StudentNode* root = (StudentNode*)malloc(sizeof(struct StudentNode));
    printf("Enter Id of the first student\n");
    scanf("%d", &id);
    root = new_node(id);
    tree = root;
    return tree;
}
struct StudentNode* new_node(int idNum) {
    struct StudentNode* Student = (StudentNode*)malloc(sizeof(struct StudentNode));
    Student->ID = idNum;
    Student->ExamGrade = 0;
    Student->MidtermGrade = 0;
    Student->parent = NULL;
    Student->left = NULL;
    Student->right = NULL;
    return Student;
}
and when i'm getting to the first line that need to change a variable in the newly built struct(Student)
Student->ID = idNum;
it throws the exception
Exception thrown: write access violation.
**Student** was 0xFFFFFFFF9A2D56F0.
 
    