The Gateway to Computer Science Excellence
0 votes

i write this program, during initialization of array i given the size as 11 means the number of elements stored in an array is 11.

as we know array is not assigned a value of index 12 and above. but in in the program array a is initialized of index from 0 to 19,my question is how the array is initialized with 20 elements although i specified size is 11.

i run in 64 bit system

int main()
	int a[11],i;



in Programming by | 208 views
Check in other compiler

I am getting runtime error
mam, check the answer by Arjun sir


@Shaik Masthan

that means in some cases a[11] array can take even 20 elements

Why compiler works so faulty? šŸ˜“



@srestha as per sir said, when you access a[12] - the behaviour in "Undefined" as per C standard.

undefined meant logic is faulty for compiler

Isnot it?

That is why it cannot able to generate genuine output

yes , i think its right..

2 Answers

+7 votes
Best answer
C is a very flexible language as it cares mainly for "performance" and "simplicity for compiler". So, if you do

int a[11];

C standard only says that you are allocated 11* sizeof(int) bytes of memory which can be accessed through the variable 'a'.

'a' being a local variable, C language does not guarantee initialization -- its value is GARBAGE. It would have been initialized to "0" had 'a' been a static or global variable.

Now, when you access a[12] - the behaviour in "Undefined" as per C standard. You can get any output and a good programmer should not care for it. Depending on the compiler implemnetation and the environment on which the program runs you can get any output including Runtime error.
by Veteran
selected by
0 votes
Bcz in c array has a problem of boundary checking.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,217 questions
59,928 answers
118,165 users