Q. What will be the output of the following code?

Code:
#include <stdio.h>
int main() {
    int i = 0;
    for(i = 0; i < 3; i++) {
        static int x = 0;
        x++;
        printf("%d ", x);
    }
    return 0;
}
  • (A) 1 1 1
  • (B) 1 2 3
  • (C) 0 1 2
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (B) 1 2 3
Explanation: Static variables retain their value between function calls/iterations.
Explanation by: Mr. Dubey
Static variables retain their value between function calls/iterations.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
70
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Mr. Dubey
Publisher
πŸ“ˆ
82%
Success Rate