Bit manipulation prob 1 whats wrong in my code ? it is compiling correctly but not showing any output

#include<bits/stdc++.h>
using namespace std;

int count_bits(int a,int b)
{
int count=0,res=0;
for(int i=a;i<=b;i++)
{

 while( (i&1)!=1)
 {
    res=(i&1);
 	count=count+res;
     i=i>>1;
}		

}

return count;
}

int main()
{
int q,num1[q],num2[q],ans[q];
cin>>q;
for(int i=0;i<q;i++)
{
cin>>num1[i]>>num2[i];
ans[i]=count_bits(num1[i],num2[i]);
}
for(int i=0;i<q;i++)
{
cout<<ans[i]<<endl;
}
return 0;
}

@gabbar_2229
Your for loop starts the value of i from a. Then the while loop begins for the first time. The while loop runs till it makes i = 1. The next time your for loop runs , it increments i=1 to i=2. It runs with value of i = 1 whereas you intended it to run for i = a+1 for the second iteration. Make the according changes to correct this.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.