ProgrammingHardGATE CS · Product company OA

Which of the objects A to E have static storage duration (they live for the whole run of the program, in the data or BSS segment)?

Which of the objects A to E have static storage duration (they live for the whole run of the program, in the data or BSS segment)?
int g;                    /* A */
static int h = 5;         /* B */
void f(void) {
    int a;                /* C */
    static int s;         /* D */
    int *p = malloc(4);   /* E: the int that p points to */
}
  1. A. B and D only
  2. B. A, B, D and E
  3. C. A and B only
  4. D. A, B and D only

Correct answer: D. A, B and D only

Every file-scope variable has static storage, with or without the static keyword (A, B), and so does a static local (D). C is automatic (stack); the malloc'd int E has allocated storage (heap), which lasts until free but is not static.

More C Programming questions

Exams that ask this topic