What will be printed out as a result of the following code execution?

#define ELEMENT_COUNT(a)\
sizeof(a)/sizeof(a[0])

int  main()
{
    int a[3] = {1,2,3};
    int* b = new int[3];
    int* c;

    cout<<ELEMENT_COUNT(a);
    cout<<ELEMENT_COUNT(b);
    cout<<ELEMENT_COUNT(c);
}
Explanation
311 will be printed out.

Constant array is given in the first case. sizeof(a) will provide us with the value of 12, and sizeof(a[0]) - with that of 4. 12/4 = 3
In the second case, sizeof(b) will provide us with the value of 4, since a is a pointer and it takes 4 bytes, sizeof(a[0]) is also equal to 4. 4/4=1
The third case is similar to the second one.

None of the available options are correct. sizeof(b) and sizeof(c) are dependent on the platform pointer size

2018 Nov 7, 9:12:25 PM

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести