C Programming MCQ Questions and Answers on Data Types and Storage Classes 3

Image
C MCQ Questions and Answers

Learn C Data Types and Storage Classes with MCQ Questions and Answers. Find questions on types of Storage Classes like Life, Scope and the default value of variables. Easily attend exams after reading these Multiple Choice Questions.

Go through C Theory Notes on Data Types and Storage Classes before studying questions.



1) Choose a correct statement regarding automatic variables.
A) #include<stdio.h>
main()

{
	auto int a;

	printf("%d", a);
}

//output is compiler error. a is not initialized.
B) #include<stdio.h>
main()

{
	auto int a;

	printf("%d", a);
}

//output = 0
C) #include<stdio.h>
main()

{
	auto int a;

	printf("%d", a);
}

//output = null
D) #include<stdio.h>
main()

{
	auto int a;

	printf("%d", a);
}

//output = some random number
Answer [=]
D
Explanation:

Yes. If an integer is not initialized, some random number in integer range will be displayed.

2) What is the output of the program.? #include<stdio.h>
int main()
{
	printf("Hello Boss.");
}
A) Hello Boss.
B) hello boss
C) No output
D) Compiler error
Answer [=]
D
Explanation:

Notice the return type int before main() method. So main should maintain a return 0; or return somenumber; statement.

3) What is the output of the program.?
int main()
{
	auto int a=10;
	{
		auto int a = 15;
		printf("%d ", a);
	}
	printf("%d ", a);
	return 1;
}
A) 10 10
B) 10 15
C) 15 10
D) Compiler error
Answer [=]
C
Explanation:

Automatic or Register variables have block scope and life. Most recent definition takes precedence. {...} is a block.

4) What is the output of the program.?
int main()
{
	register a=10;
	{
		register a = 15;
		printf("%d ", a);
	}
	printf("%d ", a);
	
	return 20;
}
A) 15 20
B) 15 10
C) 10 15
D) 15 15
Answer [=]
B
Explanation:

Automatic and Register variables have only Block Scope. Always local definition takes precedence.

5) What is the output of the C Program statement.?
register int b;
prinf("%d", b);
A) null
B) 0
C) random integer number
D) random real number
Answer [=]
C
Explanation:

auto and register variables hold garbage values by default.

6) What is the output the program.?
int main()
{
	register a=80;
	auto int b;
	b=a;
	printf("%d ", a);
	printf("%d ", b);
	
	return -1;
}
A) Compiler error. You can not assign register value to int variable.
B) 80 80
C) 80 0 Register value can not be copied.
D) Compiles, but output is none.
Answer [=]
B
7) What is the output of the program.?
void myshow();

int main()
{
	myshow();
	myshow();
	myshow();
}

void myshow()
{
	static int k = 20;
	printf("%d ", k);
	k++;
}
A) 20 20 20
B) 20 21 21
C) 20 21 22
D) Compiler error.
Answer [=]
C
Explanation:

Variable of type static holds its value until the end of program execution. Static variables do not initialize again and again with function calls.



8) What is the output of the program.? #include<stdio.h>
static int k;

int main()
{
	printf("%d", k);
	
	return 90;
}
A) -1
B) 0
C) 90
D) Compiler error
Answer [=]
B
Explanation:

Default value of a static variable is zero by default.

9) What is the output of the program.?
int main()
{
	register k = 25;
	printf("%d", &k);
	
	return 90;
}

A) prints of address of variable k.
B) 25
C) 0
D) Compiler error
Answer [=]
D
Explanation:

You can not use Ampersand & operator with a Register variable. Register is part of CPU and accessing it is not authorized.

10) The statement below is .....a
extern int p;
A) Declaration
B) Definition
C) Initialization
D) None of the above
Answer [=]
A
Explanation:

Usually, most of the C statements with extern keyword are Declarations.