QUIZ ON : C LANGUAGE - STORAGE CLASSES

STORAGE CLASSES

00:00:00

The default storage class of a ‘C’ variable is

Option A. auto
Option B. static
Option C. extern
Option D. register
True Answer A

Explanation :
The auto storage class is the default storage class for all local variables. The example above defines two variables with in the same storage class. 'auto' can only be used within functions, i.e., local variables.

The default storage class of a ‘C’ variable is

Question No# : 01 out of 15

If no storage class is mentioned for a variable defined in a function then it is by default auto.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer A

Explanation :

If no storage class is mentioned for a variable defined in a function then it is by default auto.

Question No# : 02 out of 15

Identify the storage class with which & operator cannot be used.

Option A. register
Option B. static
Option C. extern
Option D. auto
True Answer A

Explanation :
The register storage class is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size (usually one word) and can't have the unary '&' operator applied to it (as it does not have a memory location).

Identify the storage class with which & operator cannot be used.

Question No# : 03 out of 15

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

Option A. auto
Option B. dec
Option C. static
Option D. extern
True Answer B

Explanation :

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

Question No# : 04 out of 15

What is the output of the following code?

main()
{
static int num=8;
printf(“%d ”,num=num-2);
if(num!=0) main();
}

Option A. 8 6 4 2
Option B. Infinite output
Option C. 6 4 2 0
Option D. Invalid because main function can’t call itself.
True Answer C

Explanation :

What is the output of the following code?

main()
{
static int num=8;
printf(“%d ”,num=num-2);
if(num!=0) main();
}

Question No# : 05 out of 15



‘auto’ keyword is used to declare a local variable.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer A

Explanation :

‘auto’ keyword is used to declare a local variable.

Question No# : 06 out of 15

What is the output of the following code segment?

void fn() {
int a = 10;
static int b = 20;
printf("a = %d b = %d ", ++a, ++b);
}
int main() {
fn();
fn();
return 0;
}

Option A. a = 11 b = 21 a = 11 b = 21
Option B. a = 11 b = 21 a = 12 b = 21
Option C. a = 11 b = 21 a = 11 b = 22
Option D. a = 11 b = 21 a = 12 b = 22
True Answer C

Explanation :

What is the output of the following code segment?

void fn() {
int a = 10;
static int b = 20;
printf("a = %d b = %d ", ++a, ++b);
}
int main() {
fn();
fn();
return 0;
}

Question No# : 07 out of 15



What is the output of this C code?

#include <stdio.h>

void main()

{

static int x;

if (x++ < 2)

main();

}

Option A. Infinite calls to main
Option B. Run time error
Option C. Varies
Option D. main is called twice
True Answer D

Explanation :

What is the output of this C code?

#include <stdio.h>

void main()

{

static int x;

if (x++ < 2)

main();

}

Question No# : 08 out of 15



Which of the following statement is false?

Option A. Constant variables need not be defined as they are declared and can be defined later
Option B. Global constant variables are initialized to zero
Option C. const keyword is used to define constant values
Option D. You cannot reassign a value to a constant variable
True Answer A

Explanation :
Since the constant variable has to be declared and defined at the same time, not doing it results in an error.

Which of the following statement is false?

Question No# : 09 out of 15

What will be the output of the following code segment?

void fn() {
static int i = 10;
printf("%d ", ++i);
}
main() {
fn();
fn();
}

Option A. 10 10
Option B. 11 11
Option C. 11 12
Option D. 12 12
True Answer C

Explanation :

What will be the output of the following code segment?

void fn() {
static int i = 10;
printf("%d ", ++i);
}
main() {
fn();
fn();
}

Question No# : 10 out of 15



Register variable are active

Option A. outside the function
Option B. throughout the program
Option C. only in the function where it is defined
Option D. surrounding of that function
True Answer C

Explanation :

Register variable are active

Question No# : 11 out of 15

Which of the following is not a proper storage class in ‘C’?

Option A. auto
Option B. dec
Option C. static
Option D. extern
True Answer B

Explanation :

Which of the following is not a proper storage class in ‘C’?

Question No# : 12 out of 15

The default initial value of a static int variable is zero.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer A

Explanation :

The default initial value of a static int variable is zero.

Question No# : 13 out of 15

The lifetime of a static variable is the duration of your program&#39;s execution.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer A

Explanation :

The lifetime of a static variable is the duration of your program&#39;s execution.

Question No# : 14 out of 15

static storage class is used to make a variable global.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer A

Explanation :

static storage class is used to make a variable global.

Question No# : 15 out of 15