Consider the below program.
Pretty Simple program.. huh… Output will be 0.
Now if you replace arr with 0[arr], the output would be same. Because compiler converts the array operation in pointers before accessing the array elements.
e.g. arr would be *(arr + 0) and therefore 0[arr] would be *(0 + arr) and you know that both *(arr + 0) and *(0 + arr) are same.
Please write comments if you find anything incorrect in the above article.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Sum of array Elements without using loops and recursion
- How will you show memory representation of C variables?
- Difference between pointer to an array and array of pointers
- Jagged Array or Array of Arrays in C with Examples
- What’s difference between “array” and “&array” for “int array” ?
- std::transform() in C++ STL (Perform an operation on all elements)
- Sum of an array using MPI
- Pointer to an Array | Array Pointer
- Array class in C++
- How to pass an array by value in C ?
- Pointer vs Array in C
- 4 Dimensional Array in C/C++
- Array Type Manipulation in C++
- How to sort an array of dates in C/C++?
- Accessing array out of bounds in C/C++
- What is Array Decay in C++? How can it be prevented?
- How to dynamically allocate a 2D array in C?
- How to pass a 2D array as a parameter in C?
- Sum of array using pointer arithmetic
- Difference between pointer and array in C?