Suppose I want to get the last element of an automatic array whose size is unknown. I know that I can make use of the sizeof
operator to get the size of the array and get the last element accordingly.
Is using *((*(&array + 1)) - 1)
safe?
Like:
char array[SOME_SIZE] = { ... };
printf("Last element = %c", *((*(&array + 1)) - 1));
int array[SOME_SIZE] = { ... };
printf("Last element = %d", *((*(&array + 1)) - 1));
etc
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…