• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Storage Classes and Type Qualifiers

Question 21

Pick the correct statement for const and volatile.
  • const is the opposite of volatile and vice versa.
  • const and volatile can’t be used for struct and union.
  • const and volatile can’t be used for enum.
  • const and volatile can’t be used for typedef.
  • const and volatile are independent i.e. it’s possible that a variable is defined as both const and volatile.

Question 22

Pick the best statement for the following program snippet: C
#include \"stdio.h\"
void foo(void)
{
 static int staticVar;
 staticVar++;
 printf(\"foo: %d\\n\",staticVar);
}

void bar(void)
{
 static int staticVar;
 staticVar++;
 printf(\"bar: %d\\n\",staticVar);
}

int main()
{
 foo(), bar(), foo();
 return 0;
}
  • Compile error because same static variable name is used in both foo and bar. Since these static variables retain their values even after function is over, same name can’t be used in both the functions.
  • Compile error because semicolon isn’t used while calling foo() and bar() in side main function.
  • No compile error and only one copy of staticVar would be used across both the functions and that’s why final value of that single staticVar would be 3.
  • No compile error and separate copies of staticVar would be used in both the functions. That’s why staticVar in foo() would be 2 while staticVar in bar() would be 1.

Question 23

Which of the following storage classes have global visibility in C/C++ ?
  • Auto
  • Extern
  • Static
  • Register

Question 24

The following program
main()
{
inc(); inc(); inc();
}
inc()
{
static int x;
printf("%d", ++x);
}
  • prints 012
  • prints 123
  • prints 3 consecutive, but unpredictable numbers
  • prints 111

Question 25

Consider the following code fragment void foo(int x, int y) { x+=y; y+=x; } main() { int x=5.5; foo(x,x); } What is the final value of x in both call by value and call by reference, respectively?
  • 5 and 16
  • 5 and 12
  • 5 and 20
  • 12 and 20

Question 26

Consider the following pseudocode:

 x : integer := 1
 y : integer := 2
 procedure add
 x := x + y

 procedure second (P: procedure)
 x : integer := 2
 P()
 procedure first
 y : integer := 3
 second(add)
 first()
 write_integer (x)

What does it print if the language uses dynamic scoping with deepbinding?

  • 2

  • 3

  • 4

  • 5

Question 27

Which of the following is not a storage class specifier in C?
 

  • auto
     

  • register
     

  • static
     

  • extern
     

  • volatile
     

Question 28

What is the output of the following program? 
 

#include 
int tmp=20;
main( )
{
printf("%d ",tmp);
func( );
printf("%d ",tmp);
}
func( )
{
static int tmp=10;
printf("%d ",tmp);
}


 

  • 20 10 10
     

  • 20 10 20
     

  • 20 20 20
     

  • 10 10 10
     

Question 29

If only one memory location is to be reserved for a class variable, no matter how many objects are instantiated, then the variable should be declared as 

 

  • extern
     

  • static
     

  • volatile
     

  • const
     

Question 30

In C, static storage class cannot be used with:
 

  • Global variable
     

  • Function parameter
     

  • Function name
     

  • Local variable
     

There are 31 questions to complete.

Last Updated :
Take a part in the ongoing discussion