assignment-s-13-1.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 19 Dec 2025
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
Write a function that reverses the elements of an array in place, using only a single pointer argument, and return void.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
#include <stdlib.h>
void inputarr(int[], int);
void display(int[], int);
void reverse(int *);
int main()
{
int size, *arr;
printf("How many element do you want to add: ");
scanf("%d", &size);
arr = (int *)malloc((size + 1) * sizeof(int));
inputarr(arr, size);
printf("\n=== Before Reverse ===\n");
display(arr, size);
reverse(arr);
printf("\n\n=== After Reverse ===\n");
display(arr, size);
free(arr);
return 0;
}
void inputarr(int arr[], int n)
{
int i;
arr[0] = n;
for (i = 1; i <= n; i++)
{
printf("Enter element %d: ", i);
scanf("%d", &arr[i]);
}
}
void display(int arr[], int n)
{
int i;
for (i = 1; i <= n; i++)
{
printf("\nIndex: %-2d | Value: %-5d | Address: %p", i, arr[i], (void *)&arr[i]);
}
}
void reverse(int *arr)
{
int *start = arr + 1;
int size = *arr;
int *end = arr + size;
while (start < end)
{
*start = *start ^ *end;
*end = *start ^ *end;
*start = *start ^ *end;
start++;
end--;
}
}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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57