---
title: "Discussion on \"sizeof array\" | Hashnode"
description: "Discussion on \"sizeof array\". 在 C++ 中，對於陣列的大小處理，sizeof 在函式中有個容易踩雷的陷阱：如果你把陣列當作參數傳入函式，它會退化成指標。這會導致 sizeof 傳回的是指標的大小，而不是陣列的實際大小。\nExample\n#include <iostream>\n\nvoid test1(char (&a)[10]) {\n    std::cout << \"test1 called with array of si"
url: "https://hashnode.com/posts/sizeof-array/684d7107fee1801d6e4cb038"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [sizeof array](https://notes.mukyu.dev/sizeof-array?utm_source=hashnode&utm_medium=feed)

在 C++ 中，對於陣列的大小處理，sizeof 在函式中有個容易踩雷的陷阱：如果你把陣列當作參數傳入函式，它會退化成指標。這會導致 sizeof 傳回的是指標的大小，而不是陣列的實際大小。 Example #include <iostream> void test1(char (&a)\[10\]) { std::cout << "test1 called with array of si

Jun 14, 2025 · 2 min read · notes.mukyu.dev  
Updated Oct 27  
Read the article

-   [#cpp](https://hashnode.com/tag/cpp)
-   [#array](https://hashnode.com/tag/array)

## Written by

[Patchouli](https://hashnode.com/@mudream4869)

@mudream4869 · Uohout

  
[View profile](https://hashnode.com/@mudream4869)

工程師帕秋莉~

後端工程師。 不定時張貼一些寫扣時的筆記，有時英文，有時中文。 「如果，我是魔女的話...」

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
