Q:

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

belongs to collection: C pointers example programs

0

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

In this C program, we are reading 10 integer elements and printing array elements with the value and their addresses.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program

/*C program to read array elements and print with addresses.*/
#include <stdio.h>
 
int main()
{
    int arr[10];        //declare integer array
    int *pa;            //declare an integer pointer
    int  i;
     
    pa=&arr[0];         //assign base address of array
     
    printf("Enter array elements:\n");
    for(i=0;i < 10; i++){
        printf("Enter element %02d: ",i+1);
        scanf("%d",pa+i);   //reading through pointer
    }
     
    printf("\nEntered array elements are:");
    printf("\nAddress\t\tValue\n");
    for(i=0;i<10;i++){
        printf("%08X\t%03d\n",(pa+i),*(pa+i));
    }
     
     
    return 0;
}

Output

Enter array elements:
Enter element 01: 11
Enter element 02: 23
Enter element 03: 444
Enter element 04: 4
Enter element 05: 5
Enter element 06: 6
Enter element 07: 77
Enter element 08: 89
Enter element 09: 67
Enter element 10: 12

Entered array elements are:
Address			Value
E73BF180	011
E73BF184	023
E73BF188	444
E73BF18C	004
E73BF190	005
E73BF194	006
E73BF198	077
E73BF19C	089
E73BF1A0	067
E73BF1A4	012

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to count vowels and consonants in a stri... >>
<< C program to read and print student details using ...