CSE Rockz Home Blog Links Forum VSF

Saturday, January 3, 2009

Daily3

Arrays..

An array is a systamatic arrangement of things...in a scheduled order and a particular defined address...

key points:

  • arrays in c are used to contain,declare and use multiple variables
  • it becomes easy to group a certain number of variables under a single domain called an arry
  • so in this ways arrays are very benefitial for the case of multiple variables
  • arrays can be multi dimensional
  • consider a normal single dimensional  integer array and every integer occupies 2 bytes so as soon as an array of n variables is declared the systems reserves n*2 bytes of memmory under the array name say x now let us assume that first integer value is stored in a array adderss a0. so the 2nd integer will be stored at a0+2 so  nth integer is stored at ao+2*n.so general adders formula can be an= ao+t*n; where the t represents minimum size of variable eg: for float its 4
  • array declaration is done like this 
main()
{
int a[10];
}
  • array declaration should be specific ie: we cannot declare an array containing variable number of its contents eg: we cannot declare array as  int a[i] as the number of variables in it should be a constant 
  • we can read a array by writing a for loop by reading element by element 
int a[10];

for(i=0;i<10;i++)>
{
scanf("%d",&a[i]);
}

  • similarly we cant equalize two array by a single assignment ooperater we have to do it by writing a for loop

examples:

/*wap to read 10 numbers and print them using arrays*/

main()
{
int a[10],i;

printf("give the numbers");

for(i=0;i<10;i++)>
scanf("%d",&a[i]);


for(i=0;i<10;i++)>
printf("%d",&a[i]);

}

out put: 

give the numbers:
12345678910

12345678910

dryrun:


  • array is declared...
  • a printf statement is given 
  • a for loop is written to read the input
  • a forloop is writen ti print output.
  • once i=0 the loop is enterd and it prits ist number and once i=2 it prints 2nd number so on

No comments:

Post a Comment