C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 23)
23.
If the size of integer is 4bytes, What will be the output of the program?
#include<stdio.h>

int main()
{
    int arr[] = {12, 13, 14, 15, 16};
    printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
    return 0;
}
10, 2, 4
20, 4, 4
16, 2, 2
20, 2, 2
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
22 comments Page 2 of 3.

Anonimous said:   7 years ago
The answer will respect with bitwise.

If 16 bit then 10, 2, 2.

If 32bit then 20, 4, 4. Here we assume that it is 32bits.
(1)

Jignesh said:   1 decade ago
What if the array was declared as

int *arr[] = { 1,2,3,4,5 } ;

What would sizeof(arr) return ?

Maya said:   1 decade ago
@nirlep:
It is given in the question. that int is of 4 bytes, so multiply by 4 and not 2

Hemant said:   8 years ago
By size of array, it means the no of elements it can have rather than the complete size.

Viraj said:   1 decade ago
Output will be 10 2 2 on 16 bit compiler.

Pradip somase said:   2 decades ago
Thank you Pondey Ramu for description.

Nirlep said:   1 decade ago
Why multiply by 4 it should be 2?

Dinga said:   7 years ago
Thank you @N Prathyusha.

Soumya said:   1 decade ago
Thank you pondey ramu.

K SURESH said:   1 decade ago
THANK YOU PRATHYUSHA


Post your comments here:

Your comments will be displayed after verification.