MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / main

Function main

Arrays/01_static_and_dynamicArray.c:3–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include <stdio.h>
2#include <stdlib.h>
3int main()
4{
5 int A[5] = { 1,2,3,4,5 }; // this is allocated inside stack memory
6 int* p; // pointer of array
7 int i;
8 p = (int*)malloc(5 * sizeof(int)); // dynamically createing array inside heap
9 p[0] = 1; // initializing all the terms in array
10 p[1] = 2;
11 p[2] = 3;
12 p[3] = 4;
13 p[4] = 5;
14
15 for (i = 0; i < 5; i++) // iteration for normal array
16 {
17 printf("%d ", A[i]);
18 }
19 printf("\n");
20 for (i = 0; i < 5; i++) // iteration for the dynamic array
21 {
22 printf("%d ",p[i]);
23 }
24 return 0;
25}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected