Theocacao
Leopard
Design Element
Comment on "Intro to Memory and Arrays in C"
by srikanth — Feb 08
Sir,

I have written the program in this way. The array size is 16 according to the rule. But why I am able to access outside the size and how I am getting those values? I am bit confused in this. Can you please explain me Sir?
My mailId: srikanth_rongali@yahoo.co.in

#include<stdio.h>

main()
{

int array3[] = {1,2,3,4};

printf("\nSize of array3:%d.", sizeof(array3));

printf("\nValue in array3[0]: %d, array3[1]:%d, array3[2]:%d, array3[3]:%d, array3[4]:%d, array3[5]:%d, array3[6]:%d, array3[7]:%d\n", array3[0], array3[1], array3[2], array3[3], array3[4], array3[5], array3[6], array3[7]);

}

OUTPUT: I got.

Size of array3:16.
Value in array3[0]: 1, array3[1]:2, array3[2]:3, array3[3]:4, array3[4]:1, array3[5]:2, array3[6]:3, array3[7]:4

How this can be possible?
Back to "Intro to Memory and Arrays in C"
Design Element

Copyright © Scott Stevenson 2004-2015