Search Placementyogi.com
 

C Storage Classes Objective Questions and Answers

  :: Topics ::

1

Which of the following are incorrect declarations?

A.

extern int i;

B.

auto int i;

C.

static int i;

D.

register int i;

E.

global int i;

See Answer & Explanation Lets Discuss
Correct answer is : E
Explanation

All A,B,C and D are valid declarations.

extern, auto, static and register are storage classes.

There is no keyword "global" in c and hence the declaration

global int i; is invalid.

 
2

What is the output of the following program?

#include<stdio.h>
int a;
void main()
{

	auto int x=20,b;
	static int c;
	register int y=20,d;
	printf("a=%d ",a);
	printf("b=%d ",b);
	printf("c=%d ",c);
	printf("d=%d",d);
}
A.

a=0 b=Garbage Value c=0 d=Garbage Value

B.

a=Garbage Value b=Garbage Value c=0 d=Garbage Value

C.

a=0 b=0 c=0 d=0

D.

None of the above

E.

Compilation error

See Answer & Explanation Lets Discuss
Correct answer is : A
Explanation

 

By default external and static variables are initialized to 0.

auto and register variables are not assigned any value and hence contain garbage value.

Sometime it might give the values of auto and register variables as 0 but that is just a co-incidence.

Hence A is the correct answer.

 

 

 
3

What is the output of the following program?

#include<stdio.h>
int main(){
    int a=0;                     //line 3
    {
         int a=10;               //line 5
         printf("%d",a);         //line 6
         a++;                    //line 7
         {
             a=20;               //line 9
         }
         {
             printf(" %d",a);    //line 12
             int a=30; {a++;}    //line 13
             printf(" %d",a++);  //line 14
         }
         printf(" %d",a++);      //line 16
    }
    printf(" %d",a);             //line 18
    return 0;
}
A.

10 11 30 11 0

B.

10 20 31 20 0

C.

10 20 30 20 0

D.

10 20 31 20 1

E.

Compiler Error

See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

Important: The scope of an auto variable is only within the block.

 

If there is any locally declared variable with the same name as an outer block variable, local variable

is used and any modification is only reflected in the local variable.

 

But if there is no local variable with the same name, the variable from outer block is used and any modification

affects the outer block variable.

 

In the above program: 

The variable "a" at line 5 masks the "a" from line 3. line 6 prints 10.

line 7 modifies the variable "a" declared at line 5.

line 9 also modifies "a" at declared at line 5.

line 12 prints the "a" modified at line 9 and 20 is printed.

similarly line 13 declares a new variable a=30 and increments it.

So, line 14 prints 31.

line 16 has access to the variable declared at line 5 whose current value is 20 as printed in line 12.

Finally line 18 prints the variable "a" declared at line 3 which is still 0.

 
4

Consider the following declaration:

register int i;

This ensures that the variable "i" is stored in the registers of the CPU.

A. True
B. False
See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

We are merely requesting the CPU to store the variable in the registers.

It depends on the CPU whether it really allocates it on the registers or not.

 
5

What is the output of the following program?

#include<stdio.h>
int main(){
    register int a=10;
    int *p;
    p=&a;
    printf("%u",p);
}
A.

Garbage Value

B.

0

C.

10

D.

Compilation Error

See Answer & Explanation Lets Discuss
Correct answer is : D
Explanation

error: address of register variable ‘a’ requested

We can not refer the address of a register variable because it is not stored in the memory but on the registers.

Only variable stores in the memory have an address.

 
 

Banner to LogicGuns.com

Hide Page Information

C Storage Classes Objective Questions and Answers for Written Round Interview

Here you can find C Storage Classes Objective Questions with answers and explanation. We have a vast collection of Objective Questions on Storage Classes in C that will help you a lot!

Why learn C Storage Classes?

Storage Classes are an integral part of C and many Objective Questions in the written round are asked from this topic.In this section you can learn and practice C Storage Classes (Objective Questions with Answers) to improve your skills in order to face the interview and clear campus and off-campus selection of TCS, Infosys, Wipro etc.

Where can I get C Storage Classes Objective Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved C Storage Classes Objective Questions and answers with explanation. Fully solved examples with detailed answer description, explanation are given and it would be easy to understand.Though we do not have pdf file for C Storage Classes, We have quiz Objective Questions with answers to help you test yourself..

\n

Where can I get C Storage Classes Interview Objective Questions and Answers (objective type, multiple choice)?

Here you can find objective type C Storage Classes Objective Questions and answers for interview and entrance examination.Multiple Answers and true or false type Objective Questions are also provided.

How to solve C Storage Classes problems?

You can easily solve all kind of Objective Questions based on C Storage Classes by practicing the exercises (including shortcut Storage Classes to solve problems) given below.