main()
{
char buff[10];
int a;
for(int i=0; i<10;i++)
{
cin >> buff[i];
a=sizeof(buff[i]);
if(a==10)
cout << "full";
}
for(int i=0; i<10;i++)
cout << buff[i]<<"\n";
}
why des the control never comes to cout << “full”; i am new to coding…when i do dry run it works fine
Because in this code:
you are getting the size of one of the elements in the
buffarray — not of the whole array itself.And since the elements in the array are
chars, the size will always be one (as dictated by the Standard).If you are trying to get the index of the element (that is, you want to hit on the 10th element), you need to do this:
(
9instead of10because arrays are zero-based, and the 10th item is atbuff[9]. First isbuff[0], second atbuff[1], etc…)