This question has already been answered:
Dear Colleagues!
The compiler does not understand me. It is well known that the dimension of the array is int size = (sizeof(b) / sizeof(*b)); Where b is some array. So in the example below, I get the dimension of the array by putting this command into a separate function and executing this command in main :
#include "stdafx.h" #include <windows.h> #include <iostream> using namespace std; //Функция которая считает и печатает размерность массива. void ArrLength(int a[]) { int j = (sizeof(a) / sizeof(*a));; //определяем размерность массива cout << "Размерность массива в функции ArrLength = " << j << endl; } int main() { setlocale(LC_ALL, "Russian"); int b[] = {3, 5, 8, 3, 0, 32, 18, 65}; //объявление некоторого массива int size = (sizeof(b) / sizeof(*b)); //выяснение размерности некоторого массива cout << "Размерность массива size = " << size << endl; ArrLength(b); system("PAUSE"); return 0; } To my deepest surprise, prints:
Размерность массива size = 8 Размерность массива в функции ArrLength = 2 That is, it gives two different answers. And if I am ready to agree with the first, then the second seems to me obviously erroneous.
Question: what can explain the observed behavior?