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 3 of 3.

Rohan said:   7 years ago
@All.

#include<stdio.h>

int main()
{
int arr[] = {12, 13, 14, 15, 16};
printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));

/* (i) sizeof(arr) -> there are 5 elements in the arr[] , and it contains integers and size of integer is 4 bytes...
-> 5 * 4 = 20 bytes
(ii) (*arr) -> it will return 12
sizeof(*arr) -> As , 12 is an integer of 4 bytes...

(iii) sizeof(arr[0])) -> size of first element of arr[] (i.e. 4 bytes)...

*/

return 0;
}
(4)

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)


Post your comments here:

Your comments will be displayed after verification.