C Program to Access Array Elements Using Pointer

Relationship Between Arrays and Pointers Find Largest Number Using Dynamic Memory Allocation C Data Types Calculate Standard Deviation C structs and P

 To understand this example, you should have the knowledge of the following C programming topics:

·       C Arrays

·       C Multidimensional Arrays

·       Pass arrays to a function in C

·       C for Loop

·       C Arrays

·       C Pointers

·       Relationship Between Arrays and Pointers

Access Array Elements Using Pointers

 #include <stdio.h>
int main() {
    int data[5];

    printf("Enter elements: ");
    for (int i = 0; i < 5; ++i)
        scanf("%d", data + i);

    printf("You entered: \n");
    for (int i = 0; i < 5; ++i)
        printf("%d\n", *(data + i));
    return 0;
}


Output
 
Enter elements: 1
2
3
5
4
You entered: 
1
2
3
5
4
Labels : #c ,#code ,#examples ,

Post a Comment