C
candy_init
Hi,
The comparison between signed and unsigned results in the signed
quantity being made as
unsigned. Therefore, in the code:
unsigned int i = 0;
int len = -1;
for(i =0; i < len; ++i)
{
}
the loop will run a lot many times.
now consider the following code:
int funct()
{
int data[10];
data[-1] = 2;
return 0;
}
now data is equivalent to data + i * sizeof(int). Here since
sizeof returns unsigned,
therefore, data[-1] should always seek a value at an index more than
starting index 0.
But in reality, data[-1] does returns the value from the index which
is 1 before the starting
index.
So, can anyone please correct me where I am wrong?
Thanks
The comparison between signed and unsigned results in the signed
quantity being made as
unsigned. Therefore, in the code:
unsigned int i = 0;
int len = -1;
for(i =0; i < len; ++i)
{
}
the loop will run a lot many times.
now consider the following code:
int funct()
{
int data[10];
data[-1] = 2;
return 0;
}
now data is equivalent to data + i * sizeof(int). Here since
sizeof returns unsigned,
therefore, data[-1] should always seek a value at an index more than
starting index 0.
But in reality, data[-1] does returns the value from the index which
is 1 before the starting
index.
So, can anyone please correct me where I am wrong?
Thanks