• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Storage Classes and Type Qualifiers

Question 1

Output of following program? C
#include <stdio.h>
int main()
{
    static int i=5;
    if(--i){
        main();
        printf(\"%d \",i);
    }
    return 0;
}
  • 4 3 2 1
  • 1 2 3 4
  • 0 0 0 0
  • Compiler Error

Question 2

C
#include <stdio.h>
int main()
{
    static int i=5;
    if (--i){
        printf(\"%d \",i);
        main();
    }
}
  • 4 3 2 1
  • 1 2 3 4
  • 4 4 4 4
  • 0 0 0 0

Question 3

C
#include <stdio.h>
int main()
{
    int x = 5;
    int * const ptr = &x;
    ++(*ptr);
    printf(\"%d\", x);
  
    return 0;
}
  • Compiler Error
  • Runtime Error
  • 6
  • 5

Question 4

C
#include <stdio.h>
int main()
{
    int x = 5;
    int const * ptr = &x;
    ++(*ptr);
    printf(\"%d\", x);
  
    return 0;
}
  • Compiler Error
  • Runtime Error
  • 6
  • 5

Question 5

C
#include<stdio.h>
int main()
{
  typedef static int *i;
  int j;
  i a = &j;
  printf(\"%d\", *a);
  return 0;
}
  • Runtime Error
  • 0
  • Garbage Value
  • Compiler Error

Question 6

Output? C
#include<stdio.h>
int main()
{
   typedef int i;
   i a = 0;
   printf(\"%d\", a);
   return 0;
}
  • Compiler Error
  • Runtime Error
  • 0
  • 1

Question 7

C
#include<stdio.h>
int main()
{
  typedef int *i;
  int j = 10;
  i *a = &j;
  printf(\"%d\", **a);
  return 0;
}
  • Compiler Error
  • Garbage Value
  • 10
  • 0

Question 8

Output? C
#include <stdio.h>
int fun()
{
  static int num = 16;
  return num--;
}

int main()
{
  for(fun(); fun(); fun())
    printf(\"%d \", fun());
  return 0;
}
  • Infinite loop
  • 13 10 7 4 1
  • 14 11 8 5 2
  • 15 12 8 5 2

Question 9

C
#include <stdio.h>
int main() 
{ 
  int x = 10; 
  static int y = x; 
  
  if(x == y) 
     printf(\"Equal\"); 
  else if(x > y) 
     printf(\"Greater\"); 
  else
     printf(\"Less\"); 
  return 0; 
}
  • Compiler Error
  • Equal
  • Greater
  • Less

Question 10

Consider the following C function C
int f(int n) 
{ 
   static int i = 1; 
   if (n >= 5) 
      return n; 
   n = n+i; 
   i++; 
   return f(n); 
}
The value returned by f(1) is (GATE CS 2004)
  • 5
  • 6
  • 7
  • 8

There are 31 questions to complete.

Last Updated :
Take a part in the ongoing discussion