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 x ;
int main()
{
x=25;
printf(“%d”,x);
return 0;
}

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

Answer :

Ans : 4 ; extern variable get memory allocation only if we initialize in its declaration

What is the Output of following Code?
#include<stdio.h>
int main()
{
register int a=10;
int *p;
p=&a;
printf(“p val : %u”, *p);
return 0 ;
}

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

Answer :

Ans : 1 ; Register variable doesn’t have memory location

What is the Output of following Code?
#include <stdio.h>
void main()
{
val();
val();
}
void val()
{
auto int a=3;
a=a+3;
printf(“%d\n”,a);
}

  1. 6 , 6
  2. 6, 9
  3. Garbage value, Garbage value
  4. Compile time error

Answer :

Ans : 1 ; Auto variable get memory allocation every time when function execution starts

What is the Output of following Code?
#include <stdio.h>
void main()
{
auto int a=2;
{
auto int b=3;
printf(“%d,%d,”,a,b);
}
printf(“%d”,a);
}

  1. compile time error
  2. 2,3,garbage value
  3. 2,3,2
  4. garbage value, 3, 2

Answer :

Ans : 3 ;

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

  1. 3, 3
  2. 3, garbage valuee
  3. 3, 0
  4. compile time error

Answer :

Ans : 4 ; The variable-a has block scope, we cannot access from outside

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

  1. Compile time error
  2. Undefined reference to variable i
  3. 0
  4. Garbage value

Answer :

Ans : 2 ; 

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

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

Answer :

Ans : 2 ; If static variable is local, cannot be accessed from other block

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

  1. 10, 10, 10, 10, 10
  2. 10, 11, 12, 13, 14
  3. 10
  4. blank output

Answer :

Ans : 2 ;

Storage Classes – Technical – Part 2

Share this