What will be printed out as a result of the following code's execution?
#include <stdio.h>

int main() {
    int x = 5;
    0[&x] = x + x;
    printf("%d",x);
}
Explanation
Since the expression a[i] is semantically equivalent to *(a+i), which in turn is equivalent to *(i+a), the expression can also be written as i[a], which is 0[&x] and means accessing the value, to which pointer to x points, that is *(0+&x). More information: ways to access elements of an array .

Pretty sure this answer is wrong. You can't apply the index operator to an integer constant, and pointer arithmetic requires the compiler to know the size of the type pointed to. For this code to work you would first have to cast 0 to a char pointer.

2018 Nov 7, 9:34:07 PM

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты