Programming
What is the output of this C program?
#include<stdio.h>
void main()
{
int a[10];
a[19] = 20;
printf("%d",a[19]);
}
Output:
20Explanation :
There is no "index out of bound" concept in C language. It allocates memory for array continuously in memory without take care of range. So whatever the index, it allocates memory for it and execute without error.If you use the all array indexes then also it execute and gives the output as you expected but It raises an error.
Ex:
#include<stdio.h>
void main()
{
int a[10],i;
for(i=0;i<20;i++)
{
a[i]=i;
printf("%d",a[i]);
}
}
Output:
*** stack smashing detected ***: <unknown> terminated
012345678910111213141516171819Aborted (core dumped)
Comments
Post a Comment