📘 Lesson  ·  Lesson 56

Arrays and Pointers

Arrays and Pointers

Arrays and Pointers

💡 Note

An array name acts like a pointer to its first element. You can use pointer arithmetic to move through an array.

Example

C
#include <stdio.h>
int main() {
    int a[] = {10, 20, 30};
    int *p = a;          // points to a[0]
    printf("%d\n", *p);       // 10
    printf("%d\n", *(p+1));   // 20
    printf("%d\n", *(a+2));   // 30
    return 0;
}
Output:
10 20 30

Summary

  • An array name is the address of its first element.
  • *(a+i) is the same as a[i].

Arrays और Pointers

💡 Note

Array name पहले element का pointer की तरह काम करता है। Pointer arithmetic से array में घूम सकते हैं।

Example

C
#include <stdio.h>
int main() {
    int a[] = {10, 20, 30};
    int *p = a;          // a[0] को point करता है
    printf("%d\n", *p);       // 10
    printf("%d\n", *(p+1));   // 20
    printf("%d\n", *(a+2));   // 30
    return 0;
}
Output:
10 20 30

सारांश

  • Array name उसके पहले element का address है।
  • *(a+i) वही है जो a[i]
← Back to C Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n