#CCBCHBAHAI0000103. Bẫy sizeof khi array đi vào hàm
Bẫy sizeof khi array đi vào hàm
The sizeof Trap for Array Parameters
Source: Phuoc Hung OJ
Version: Phuoc Hung OJ Extended
Problem
Consider a real C array object declared at the caller as int a[N];, where is a positive compile-time constant in the conceptual program. For the expression sizeof(a) / sizeof(a[0]):
- context
0: it is evaluated in the block whereais still an array object, so it yields ; - context
1: it is evaluated inside a function parameter declaredint a[]; that parameter is adjusted toint *, sosizeof(a)is the size of a pointer and the original array length cannot be portably recovered from this expression.
Answer each context query.
Input
The first line contains . The second line contains values from .
Output
For context 0 print ; for context 1 print UNKNOWN, one answer per line.
Subtask
Subtask 1 (20 points): .
Subtask 2 (30 points): , .
Subtask 3 (50 points): , .
Example
Input
8 4
0 1 0 1
Output
8
UNKNOWN
8
UNKNOWN
Explanation
At the declaration site a is an array; as a function parameter it is adjusted to a pointer.