Logo F2FInterview

C Interview Questions

Q   |   QA

Static variable is a variable that has visibility of a local variable and life time of an external variable. It is stored in main memory and has default value zero.

Example:

#include <stdio.h>

//program in file f1.c

void count(void) {
     static int count1 = 0;
     int count2 = 0;
     count1++;
     count2++;
     printf("\nValue of count1 is %d, Value of count2 is %d", count1, count2);
}

/*Main function*/

int main(){
    count();
    count();
    count();
    return 0;
}

Output:
Value of count1 is 1, Value of count2 is 1
Value of count1 is 2, Value of count2 is 1
Value of count1 is 3, Value of count2 is 1

 Auto variables are stored in main memory and their default value is a garbage value. 

Global, static, local :  In main memory

Register variable: In registers

C program : In main memory

Evaluation of any expression is from left to right. Preincrement is faster because it doesn't need to save the current value for next instruction whereas Postincrement needs to saves current value to be incremented after execution of current instruction.

Functions in header file are declared.

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: