
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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".
- Related Articles
- What is Array Decay in C++?
- What is an array in C#?
- What is an array class in C#?
- What is a multidimensional array in C language?
- How to plot Exponentially Decaying Function using FuncAnimation in Matplotlib
- What is the simplest multi-dimensional array in C#?
- What is an array of structures in C language?
- What is a one-dimensional array in C language?
- What is a two-dimensional array in C language?
- What is a multi-dimensional array in C language?
- What is Image Array? Explain with an example in C++
- What is Array Decay in C++? How can it be prevented?
- What is out of bounds index in an array - C language?
- What is Array in PowerShell?
- What is a reference/ref parameter of an array type in C#?

Advertisements