Code:
//This program prints the initialize value and the addresses of the
//elements inside the array. This proram also allows the user to change
//the address of the hardcoded number in the program.
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define ARRAY_SIZE 4
int main(){
//Declare variable
int x=1,rep;
char error[128];
// Declare array
int arr[]={1,2,3,4};
//Declare pointer
int *ptr;
system("cls");
//Show value of array elements
printf("The value of elements inside the array:\n\n");
for(int i=0;i<ARRAY_SIZE;i++){
printf("Value of element %d: %d\n",i,arr[i]);
}
//Print addresses of array elements
printf("The addresses of elements inside the array:\n\n");
for(int i=0;i<ARRAY_SIZE;i++){
ptr = &arr[i];
printf("Address of element %d: %p\n",i,ptr);
}
//Show value of variable
printf("Value of x: %d\n",x);
//Print address of variable
ptr=&x;
printf("Address of x: %p\n",ptr);
//Input address
int temp=0;
printf("Please input an address: ");
scanf("%d",&temp);
*ptr = temp;
//Print input
printf("Your input: %p\n", *ptr);
Code:
printf("Please press the spacebar to continue!!");
getche();
system("cls");
do{
system("cls");
printf("Do you want to repeat the computation?\n\n");
printf("1 - Yes\n");
printf("2 - No\n");
scanf("%s",&error);
rep=atoi(error);
switch(rep){
case 1:
main();
break;
case 2:
break;
default:
system("cls");
printf("Invalid input. Please try again!!!\n");
printf("Please press the spacebar to continue!!");
getche();
break;
}
}while(rep>2||rep<1);
}


