C Programming | Difference Between Array and Pointer Variable Size with Example | 04

Опубликовано: 31 Март 2026
на канале: Gate Instructors
12,903
82

Playlist for all videos on this topic:    • Programming and Data Structures  Video Lec...  
Arrays, introduction to, data structures, algorithms, lectures, in c, hindi, gate, interview questions and answers, iit, tutorial, Data Structures, Algorithm, Lecture, for, GATE, in Hindi, tutorial, beginners, analysis, lecture, world, iit, algorithm analysis and
design lecture, An array is a fixed-length collection of objects, which are stored sequentially in memory. There are only three things you can do with an array: sizeof - get its size You can apply sizeof to it. An array x of N elements of type T (T x[N]) has the size N * sizeof (T), which is what you should expect. For example, if sizeof (int) == 2 and int arr[5];, then sizeof arr == 10 == 5 * 2 == 5 * sizeof (int).
& - get its address You can take its address with &, which results in a pointer to the entire array.
any other use - implicit pointer conversion Any other use of an array results in a pointer to the first array element (the array "decays" to a pointer).That's all. Yes, this means arrays don't provide direct access to their contents. More specifically, there is no array indexing operator. Pointers A pointer is a value that refers to another object (or function). You might say it contains the object's address. Here are the operations that pointers support: sizeof - get its size
Like arrays, pointers have a size that can be obtained with sizeof. Note that different pointer types can have different sizes.
& - get its address
Assuming your pointer is an lvalue, you can take its address with &. The result is a pointer to a pointer.
- dereference it
Assuming the base type of your pointer isn't an incomplete type, you can dereference it; i.e., you can follow the pointer and get the object it refers to. Incomplete types include void and predeclared struct types that haven't been defined yet.
+, - - pointer arithmetic
If you have a pointer to an array element, you can add an integer amount to it. This amount can be negative, and ptr - n is equivalent to ptr + -n (and -n + ptr, since + is commutative, even with pointers). If ptr is a pointer to the i'th element of an array, then ptr + n is a pointer to the (i + n)'th array element, unless i + n is negative or greater than the number of array elements, in which case the results are undefined. If i + n is equal to the number of elements, the result is a pointer that must not be dereferenced.
That's it, really. However, there are a few other pointer operations defined in terms of the above fundamental operations:
struct dereference
p arrow m is equivalent to (*p).m, where . is the struct/union member access operator. This means p must be a pointer to a struct or union.
[] - indexed dereference
a[b] is equivalent to *(a + b). This means a and b must be a pointer to an array element and an integer; not necessarily respectively, because a[b] == *(a + b) == *(b + a) == b[a]. Another important equivalence is p[0] == 0[p] == *p.