K
klays
Hi all,
I have created char array, when I use tab[-10] compiler shouts out:
error: size of array 'tab' is negative
I tried to cheat compiler and a little modify this code.
Look at the code:
void check(int lenght, int index) {
char tab[lenght];
tab[index] = 'a';
printf("Character: %c, Sizeof: %d", tab[index], sizeof(tab));
}
Call:
check(-10, -2);
Output:
Character: a, Sizeof: -10
My questions are:
answer = Is it correct initializing array?
if (YES == answer) {
Why do compiler allow to this instruction?
}
else
{
Why not ?
}
Please, explain me it.
Thanks in advance
Klays
I have created char array, when I use tab[-10] compiler shouts out:
error: size of array 'tab' is negative
I tried to cheat compiler and a little modify this code.
Look at the code:
void check(int lenght, int index) {
char tab[lenght];
tab[index] = 'a';
printf("Character: %c, Sizeof: %d", tab[index], sizeof(tab));
}
Call:
check(-10, -2);
Output:
Character: a, Sizeof: -10
My questions are:
answer = Is it correct initializing array?
if (YES == answer) {
Why do compiler allow to this instruction?
}
else
{
Why not ?
}
Please, explain me it.
Thanks in advance
Klays