BST kth smallest element logic error

Hi so i have implemented this logic while finding out the kth smallest element in a bst could someone tell me if its right or wrong and correct the logic if it is wrong.

Heading #### void inorder(TreeNode *root,int arr[],int count)

{

if(root!=NULL)
{

inorder(root->left,arr,count);

arr[count]=root->val;

count++;

inorder(root->right,arr,count); }

}

int Solution::kthsmallest(TreeNode* root, int k) {

int arr[1000];

int barr;

inorder(root,arr,0);

for(int i=1;i<=k;i++)

{

barr=arr[i];

}

return barr;