C Technical Interview Questions on Storage Classes

These C Technical Interview Questions on Storage Classes post providing basic, intermediate and Hard level examples in C Storage Classes. The Practice of these examples makes you good in C programming.


What is the Output of following Code?
#include <stdio.h>
extern int i;
int main()
{
printf(“%d”,i);
return 0;
}

  1. Compile time error
  2. Runtime error
  3. 0
  4. Garbage value

Answer :

Ans : 2 ; Memory will not be allocation to variable-i unless we initialize

What is the Output of following Code?
#include <stdio.h>
static int i=25;
int main()
{
printf(“%d”,i);
return 0;
}
static int i=20;

  1. 25
  2. 20
  3. Compile time error
  4. Runtime error

Answer :

Ans : 3 ; Re-declaration of variable

What is the Output of following Code?
#include <stdio.h>
int main()
{
int a ;
printf(“%d”,a);
return 0;
}

  1. Compile time error
  2. 0
  3. Garbage value
  4. Runtime error

Answer :

Ans : 3 ; Local variable initializes with garbage values

What is the Output of following Code?
#include <stdio.h>
int main()
{
static int a;
printf(“%d”,a);
return 0;
}

  1. Compile time error
  2. Garbage value
  3. 0
  4. Runtime error

Answer :

Ans : 3 ; Static variable initial value is 0 either it is local or global

What is the Output of following Code?
#include <stdio.h>
extern int i;
int main()
{
i=25;
printf(“%d”,i);
return 0;
}
int i=10;

  1. 10
  2. 25
  3. 0
  4. Runtime error

Answer :

Ans : 2 ; 

What is the Output of following Code?

#include <stdio.h>
void main()
{
val();
val();
}
void val()
{
static int a=3;
a=a+3;
printf(“%d\n”,a);
}

  1. 6, 6
  2. 6, 9
  3. Compile time error
  4. None of the above

Answer :

Ans : 2 ; static variable memory releases only when program execution completes

What is the Output of following Code?
#include <stdio.h>
void main()
{
const int x=5;
const int *ptrx;
ptrx = &x;
*ptrx = 10;
printf(“%d\n”, x);
return 0;
}

  1. Compile time error
  2. 5
  3. 10
  4. 0

Answer :

Ans : 1 ; Cannot modify const variable

 Command Line Arguments – Technical

Share this