Linear Array using Pointer
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int *a; // Pointer
int size;
printf("Size of an array: ");
scanf("%d", &size);
// malloc()- it allocates the memory dynamically to a pointer variable
a = malloc(sizeof(int) * size);
printf("Enter %d elements of an array: ");
for (int i = 0; i < size; i++)
scanf("%d", &a[i]); // Behaving like an array
printf("You've entered: ");
for (int i = 0; i < size; i++)
printf("%d ", a[i]);
printf("\n");
return 0;
}
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int *a; // Pointer
int size;
printf("Size of an array: ");
scanf("%d", &size);
// malloc()- it allocates the memory dynamically to a pointer variable
a = malloc(sizeof(int) * size);
printf("Enter %d elements of an array: ");
for (int i = 0; i < size; i++)
scanf("%d", &a[i]); // Behaving like an array
printf("You've entered: ");
for (int i = 0; i < size; i++)
printf("%d ", a[i]);
printf("\n");
return 0;
}
Comments
Post a Comment
Post Your Valuable Comments