I have come across a strange behavior..
#include <stdio.h>
#include <conio.h>
int strlen(const char *);
int main()
{
char str[]="rahul";
printf("%d",strlen(str));
_getch();
return 0;
}
int strlen(const char *str)
{
const char *eostr=str;
while(*eostr++);
return eostr - str;
}
Outputs :
In VS9 Length:6 // correct
In gcc Length:5 //a less iteration ... why it is??
In devcpp Length:6 //correct
If I edit the strlen function as
int strlen(const char *str)
{
const char *eostr=str;
while(*eostr)
eostr++;
return eostr - str;
}
Now output:
n VS9 Length:5 // correct
In gcc Length:5 //still 5.. same no of iteration
In devcpp Length:5 //correct
Any idea please??
Cheers!!