📘 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
10 20 30
Summary
- An array name is the address of its first element.
*(a+i)is the same asa[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
10 20 30
सारांश
- Array name उसके पहले element का address है।
*(a+i)वही है जोa[i]।