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 */
}- A. B and D only
- B. A, B, D and E
- C. A and B only
- 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
- What is printed? c int cmp(const void a, const void b) { return (const int )b - (const int )a; } int main(void) { int v[] = {4, 9, 1, 7}…
- What is printed? c printf("%d %d %d", atoi("42abc"), atoi(" -7x"), atoi("x9"));
- What is printed? c int a = 0, b = 0; int n = sscanf("12 abc 7", "%d %d", &a, &b); printf("%d %d %d", n, a, b);
- With 4-byte int, what is printed? c int p = (int[]){10, 20, 30}; p[1] += 5; printf("%d %zu", p[1] + p[2], sizeof((int[]){10, 20, 30}) /…
- What is printed? c #define COUNT(...) (sizeof((int[]){VAARGS}) / sizeof(int)) printf("%zu %zu", COUNT(1, 2, 3), COUNT(7));
- After the call below, what is c? c int c = 0; void perm(char s, int k, int n) { if (k == n) { c++; return; } for (int i = k; i < n; i++) {…