Skip to main content

Posts

Showing posts with the label Static memory allocation in C

Arrays and static Memory allocation in C

In this post we will be talking about array, their usage and importance in C. Array Array in simple world is a collection/container of elements of  same type. Array of any type is possible but the elements in array cannot be of multiple types. We can have array of int type. But not a array with 5 element of int and other element of other types . Why Array? Imagine a problem where you want to input the marks of 10 student in a subject  from the user and display the marks in descending number. Our major problem above will be to store the number input by the user. Here we have two options : Either construct 10 variables for storing marks of 10 student .(A trash Idea) Or Construct a container (Array of integers in this case) which can store all the marks of student . First Glance of an Array As mentioned earlier array is a nothing else than a collection for us. int   marks [ 10 ]  =  { ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' }; This is what an array lo