what will be the output

1 view
Skip to first unread message

Neha

unread,
Feb 28, 2011, 12:59:01 PM2/28/11
to Knowledge Test
what will be the output of the following code...
will it generate an error or warning or will give an output?

void main()
{
int a[]={};
printf("%d",sizeof(a));
getch();
}



assume header files are included....

akanksha shukla

unread,
Mar 1, 2011, 12:25:55 PM3/1/11
to knowledge-...@googlegroups.com
It will definitely give an error..

Ravina soni

unread,
Mar 1, 2011, 12:44:41 PM3/1/11
to knowledge-...@googlegroups.com
 yes it will give error........

@Neha plz post  ans also...... after some reply .......so everyone will get to knw the correct result  

NEHA PORWAL

unread,
Mar 1, 2011, 12:47:49 PM3/1/11
to knowledge-...@googlegroups.com


ya i'll surely try to answer in much simpler language.....

TheSuyog

unread,
Mar 2, 2011, 3:56:35 AM3/2/11
to Knowledge Test
The compiler does not identify {} as any recognizable expression. The
array definition: int a[] = { 1, 2, 3}; allocates memory spaces to the
elements and evaluates the memory address which is assigned to the
array name 'a', a pointer. Hence only {} can not evaluate to
anything, that's why it generates an error. I hope I've made it
clear. :)

akanksha shukla

unread,
Mar 2, 2011, 7:45:18 AM3/2/11
to knowledge-...@googlegroups.com
@ himanshu :yups.. :)

Ravina soni

unread,
Mar 3, 2011, 1:22:55 PM3/3/11
to knowledge-...@googlegroups.com


@ himanshu  thankx
Reply all
Reply to author
Forward
0 new messages