Q:

Making my own array in c:

I am beginner in C. I want to make an array whose size will be taken from user from scanf function because an array may have any size which is not known when program starts.
And how can I input array element as well:
I will like to have my program output as:
Please enter the number of array element: 4
Enter the elements: 12 43 5 6
The elements you entered are: 12 43 5 6
Is it possible to do this? How can I make my output like this?

A:

Yes it is very possible. It is called dynamic memory allocation.
What you would do is create a pointer and then allocate it
later. 
int *array;
int num_elements;
//Get number of elements here
array = (int *)malloc(sizeof(int) * num_elements);
if(!array){ //Good practice to check if the allocation worked
    printf("Allocating %d bytes failed\n", (int)sizeof(int) * num_elements);
    return -1;
}
//Use the array are normal
free(array); // don't forget to free allocated memory

Pointer access works just like a static array i.e. array[0] = whatever
edit:
Don't forget you should include stdlib.h when using malloc()

A:

Dynamic memory work well to your purpose, however as mention earlier by Gopi, C99 allow you to directly use the stack.
Here is another solution using stack instead of heap memory:
    #include <stdio.h>

    int     main(void)
    {
      int   nb;

      scanf("%d", &nb);
      printf("%d\n", nb);
      // declaration
      char  my_tab[nb];
      if  (nb > 2)
        {
          // I use my table as I want...
          my_tab[0] = 'a';
          my_tab[1] = 0;
          printf("%s\n", my_tab);
        }
      return (0);
    }

I hope this will help you understand better, the different kind of memory allocation.

