960 views
8 8 votes
#include <stdio.h>
void fun() {
    static int count = 0;
    count++;
    printf("%d ", count);
}
int main() {
    for (int i = 0; i < 3; i++)
        fun();
    return 0;
}

What is the output of the above C program?

  1. $111$
     
  2. $012$
     
  3. $123$
     
  4. $321$

6 Answers

1 1 vote

The variable count is declared as static, so it retains its value between function calls. Each time fun() is called, count increases by 1 and prints its value.

so, Ans- c. 123

0 0 votes

The correct answer is Option C) 123

the static variables are initialised once, and they have lifetime during the program.

Position:
Show:

Related questions

9 9 votes
2 2 answers
1.2k
1.2k views
GO Classes asked Jul 25, 2025
1,192 views
#include <stdio.h struct Point { int x, y; }; int main() { struct Point p1 = {10, 20}; struct Point *ptr = &p1; ptr->x += 5; (*ptr).y -= 10; printf("%d %d\n", p1.x, p1.y)...
4 4 votes
1 1 answer
627
627 views
GO Classes asked Jul 25, 2025
627 views
Which of the following expressions is NOT equivalent to ${ }^*(\operatorname{arr}+3)$ where arr is an integer array?$\operatorname{arr}[3]$ *(&arr $[0]+3)$ $* a r r+3$ $*...
5 5 votes
3 3 answers
673
673 views
GO Classes asked Jul 25, 2025
673 views
Given the pseudocode below for the function remains(), which of the following statements is true about the output, if we pass it a positive integer $n>2$ ? int remains(in...
9 9 votes
2 2 answers
641
641 views
GO Classes asked Jul 25, 2025
641 views
Consider the following psuedocode fragment, where $y$ is an integer that has been initialized.int i=1 int j=1 while (i<10): j=j*i i=i+1 if (i==y): break end if end whileC...