Write C program to read array elements and print the value with the addresses


Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Write C program to read array elements and print the value with the addresses


  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int arr[10]; //declare integer array
  6. int *ptr; //declare an integer pointer
  7. int i;
  8.  
  9. ptr=&arr[0]; //assign base address of array
  10.  
  11. printf("Enter array elements:\n");
  12. for(i=0;i < 5; i++){
  13. scanf("%d",ptr+i); //reading through pointer
  14. }
  15.  
  16. printf("\nEntered array elements are:");
  17. printf("\nAddress\t\tValue\n");
  18. for(i=0;i<5;i++){
  19. printf("%08X\t%03d\n",(ptr+i),*(ptr+i));
  20. }
  21.  
  22.  
  23. return 0;
  24. }
  25.  

Result

C language techstudy.org

     





Related Topics




Popular Posts