One of my friend gave me this code to run it on my computer.
I couldn’t understand the output.
Here is the code:
#include<stdio.h>
void main()
{
int i;
int ar[]={1,2,3,4};
for(i=0;ar[i]!=NULL;i++);
printf("%d",i);
}
OUTPUT: 25
If I change the code to this, the output changes quite dramatically:
#include<stdio.h>
void main()
{
int i;
int ar[]={0,1,2,3,4}; //There is an extra element ‘0’ in the first position.
for(i=0;ar[i]!=NULL;i++);
printf("%d",i);
}
OUTPUT: 0
So, it looks like 0 here is considered as a NULL value, which is really weird.
Can you guys please help me understand the problem?