forked from kautukraj/Lab6C
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1Copy.c
More file actions
27 lines (25 loc) · 728 Bytes
/
1Copy.c
File metadata and controls
27 lines (25 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* Implementation of dynamic memory allocation in C */
/* Author : Kautuk Raj */
#include <stdio.h>
#include <stdlib.h>
void read_print(); // function prototype
int main()
{
read_print(); // calling the function
return 0;
}
void read_print()
{
int n, i;
scanf("%d", &n);
int* p = (int*)malloc(n * sizeof(int)); /* using malloc function to allocate memory as per our needs */
for (i = 0; i < n; i++)
{
scanf("%d", (p + i)); /* scanning using the address of memory */
}
for (i = 0; i < n; i++)
{
printf("%d ", *(p + i)); /* printing the value using * operation (dereferencing) */
}
free(p); /* freeing up the allocated memory space */
}