0

Here I am having a array of 4 elements but the it prints the value as 11 so how does the size has become 11 instead of 4

array set ipname {UART TEST SPI I2C}
set bsize [array size ipname];
puts "$bsize"

1 Answer 1

2

The array set (which only makes two elements in your case!) does not remove any existing contents of the array, which must have had between 9 and 11 elements in it previously. If I run your code in a bare tclsh, it prints 2. If I then follow up with parray, it tells me what it did:

% parray ipname
ipname(SPI)  = I2C
ipname(UART) = TEST
Sign up to request clarification or add additional context in comments.

2 Comments

Once we have 4 elements in a array it will give correct size only if its size increased ?? i.e if the elements are reduces it always gives 4 and if more than 4 it provides accurate result ?
Try: set bsize [llength [array names ipname]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.