In: Computer Science
C++ please. Define a problem with user input, user output, Pointer, with const and sizeof operator.
If you have any queries please comment in the comments section I will surely help you out and if you found this solution to be helpful kindly upvote.
Solution :
#include <iostream>
using namespace std;
// main function
int main()
{
// declare an integer
int a;
// input the integer
cin>>a;
// create constant size for the array
const int size = a;
// declare a dynamic array using pointer
int *arr;
// initialize the array using malloc and sizeof
arr = (int*)malloc(size * sizeof(int));
// input array elements
for(int i=0;i<size;i++)
{
cin>>arr[i];
}
// print array elements
for(int i=0;i<size;i++)
{
cout<<arr[i]<<" ";
}
return 0;
}