After compiling the following program I get the output "2346" but was expecting "2345".
#include<math.h>
#include<iostream.h>
int nr_cif(int a)
{
    int k=0;
    while(a!=0)
    {
        a = a/10;
        k++;
    }
    return k;
}
void Nr(int &a){
    int k = nr_cif(a);
    a = a % (int)pow(10,k-1);
}
int main()
{
    int a = 12345;
    Nr(a);
    cout<<a;
}
After debugging I noticed that it bugs out after it evaluates: a = a % (int)pow(10,k-1). Why does it break here?