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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- How will you show memory representation of C variables?
- What’s difference between “array” and “&array” for “int array” ?
- Sum of array Elements without using loops and recursion
- Pointer to an Array | Array Pointer
- Difference between pointer to an array and array of pointers
- Jagged Array or Array of Arrays in C with Examples
- Array of Structures vs. Array within a Structure in C/C++
- std::transform() in C++ STL (Perform an operation on all elements)
- Why C treats array parameters as pointers?
- Pointer vs Array in C
- Do not use sizeof for array parameters
- What is the difference between single quoted and double quoted declaration of char array?
- Are array members deeply copied?
- How to pass a 2D array as a parameter in C?
- How to dynamically allocate a 2D array in C?
- What is Array Decay in C++? How can it be prevented?
- How to print size of array parameter in C++?
- How to create a dynamic 2D array inside a class in C++ ?
- How to find size of array in C/C++ without using sizeof ?
- Array algorithms in C++ STL (all_of, any_of, none_of, copy_n and iota)