This blog is under construction

Sunday 6 May 2012

Array initialization at runtime in C

Arrays can be initialized at run time.  Below is an example for array initialization at run time.

Example: 
      int num[5];
      for (i = 0; i < 5; i++)
              num[i] = i * 10;


Example C program for array initialization at run time

#include <stdio.h> 
  int main() {
        int val[5], i;
        /* initializing array during run time */
        for (i = 0; i < 5; i++) {
                val[i] = (i+1) * 10;
                printf("%d\t", val[i]);
        }
        printf("\n");
        return 0;
  }

  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  10    20    30    40    50   


1 comment:

  1. Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051

    ReplyDelete