0 0 votes Under which of the following conditions, the size of an one-dimensional array need to be specified ? a) when initialization is a part of definition b) when it is a declaration c) when it is a formal parameter or actual parameter d) none of the above Programming in C + – Nishu 7.0k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 2 2 votes Option (d) None of the above is correct. Because, When Initialization is a part of declaration then we do not need the size. In the declaration also we do not need to give the size of array. eg. extern int abc[]; is saying that refer to an global array abc defined in some file. Similarly when we use that as formal and actual parameter, we do not have to give the size. It will passed as a separate variable. rude answered Mar 22, 2016 • selected Jun 10, 2016 by rude rude comment Share Follow See all 3 Comments 3 3 Comments reply rude commented May 19, 2016 reply Follow flag @Arjun Sir, please verify this. 0 0 replyShare Arjun commented May 19, 2016 reply Follow flag The last part is not correct. C compiler by default won't figure out the size of an array passed as an argument to a function. For this reason, we must pass the no. of elements in the array too. 1 1 replyShare rude commented May 20, 2016 reply Follow flag Absolutely sir. Thanks. 0 0 replyShare Please log in or register to add a comment.
1 1 vote b) when it is a declaration Anurag_s answered Mar 14, 2016 • reshown Mar 14, 2016 by Arjun Anurag_s comment Share Follow See all 8 Comments 8 8 Comments reply ManojK commented Mar 14, 2016 reply Follow flag @Arjun Sir Is it mandatory to specify while declaration?? 0 0 replyShare Arjun commented Mar 14, 2016 reply Follow flag Sorry. no. If we don't give, it is taken as a pointer. 0 0 replyShare ManojK commented Mar 14, 2016 reply Follow flag thanks 0 0 replyShare Anurag_s commented Mar 14, 2016 reply Follow flag In case of dynamically allocated array , we can give w/o size while declaration but i am not sure to consider that or not here. eg int * a; a=(int *)malloc(n*sizeof(int)); 0 0 replyShare srestha commented Mar 14, 2016 reply Follow flag yes if it is dynamically allocated , then size is not specified 0 0 replyShare Arjun commented Mar 14, 2016 reply Follow flag @Anurag there is no dynamic array in C. int * a; //a is a pointer here a = malloc(...) // a gets a value we can give extern int a[]; in C and this is a declaration saying a is an array defined as global in some file. 1 1 replyShare srestha commented Mar 14, 2016 reply Follow flag @Arjun sir http://www.geeksforgeeks.org/dynamically-allocate-2d-array-c/ 0 0 replyShare Arjun commented Mar 14, 2016 reply Follow flag @srestha there a dynamic array is created using malloc- yes, we can create a dynamic array of memory using C language. But C does not have inbuilt dynamic arrays- all arrays are considered static by the C compiler. 3 3 replyShare Please log in or register to add a comment.