1. Home
  2. Computer Science MCQs
  3. C Programming
  4. int a[n]; is declared inside a function, with n supplied…

Added 30 Nov -0001

int a[n]; is declared inside a function, with n supplied at run time. When is sizeof(a) evaluated, and what does it yield?

  1. At run time, giving n times the element size, with no compile-time constant Correct answer
  2. At compile time, giving the maximum size the array could possibly take
  3. At run time, giving the address of the last element instead of a byte size value
  4. At compile time, giving the size of a pointer because a is an array name

Correct answer

A. At run time, giving n times the element size, with no compile-time constant

19 views

MCQSEXAM

Explanation

An array whose bound is not a constant expression is a variable length array, and sizeof applied to it is evaluated at run time, producing n times the element size in bytes. Ordinary arrays of constant size are measured at compile time, which is why sizeof is usually a constant expression. The catch is that the result has type size_t but the value cannot be used as a case label or in a static initialiser.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs