- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is array decaying in C/C++?
Arrays and pointers work quite similarly in C/C++. But there are some subtle differences. For example, the sizeof operator works quite differently on the two. When you convert an array in a pointer,
Example
#include<iostream> int main() { const int a[] = { 2, 3, 5, 7, 11 }; const int* p = a; std::cout << ( sizeof(p) != sizeof(a) ); }
Output
This gives the output −
1
The sizeof operator on the pointer actually gives the size of the pointer rather than that of the array. This loss of ability of a pointer is called "decay".
Advertisements