What will be the output of the program ? int main() { float arr[] = {12.4,…

2024

What will be the output of the program ?

int main()

{

float arr[] = {12.4, 2.3, 4.5, 6.7};

printf("%d\n", sizeof(arr)/sizeof(arr[0]));

return 0;

}

  1. A.

    4

  2. B.

    5

  3. C.

    6

  4. D.

    7

Attempted by 612 students.

Show answer & explanation

Correct answer: A

Explanation:

The array arr is declared with 4 elements: 12.4, 2.3, 4.5, and 6.7.

The expression sizeof(arr)/sizeof(arr[0]) calculates the number of elements in the array.

sizeof(arr) gives the total size of the array in bytes, and sizeof(arr[0]) gives the size of one element.

Since the array has 4 elements, the result of the division is 4.

The printf statement prints the result, which is 4.

Explore the full course: Coding For Placement