Declaration(C++ Programming ) Questions and Answers
Explanation:-
Answer: Option A. -> char*The statement makes CHAR a synonym for char*.
Explanation:-
Answer: Option C. -> Statement 1 and 3 are wrongIn statement 1 lvalue is required as unary ‘&’ operand and in statement 3 lvalue is required as
left operand.
Question 3.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int a = 10;
6.
if (a < 10) {
7.
for (i = 0; i < 10; i++)
8.
cout
- 0123456789
- 123456789
- 0
- error
Explanation:-
Answer: Option D. -> errorWe will get compilation error because ‘i’ is an undeclared identifier.
Question 4.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
void addprint()
4.
{
5.
static int s = 1;
6.
s++;
7.
cout
- 234
- 111
- 123
- 235
Explanation:-
Answer: Option A. -> 234The variable that is declared as static has a file scope.
Output:
$ g++ dec2.cpp
$ a.out
234
Explanation:-
Answer: Option C. -> Yes, but not a very efficient way to write programs.We can declare variables with the same name in two functions because their scope lies within the
function.
Question 6.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
int g = 100;
4.
int main()
5.
{
6.
int a;
7.
{
8.
int b;
9.
b = 20;
10.
a = 35;
11.
g = 65;
12.
cout
- 2035655065
- 2035655035
- 2035635065
- none of the mentioned
Explanation:-
Answer: Option A. -> 2035655065The local values of a and g within the block are more dominant than the global values.
Output:
$ g++ dec1.cpp
$ a.out
2035655065
Explanation:-
Answer: Option D. -> 1 declares i,2 declares and defines iThe keyword extern is not a definition and is not allocated storage until it is initialized.
Explanation:-
Answer: Option C. -> only 4No extern are allowed for class declarations.
Explanation:-
Answer: Option C. -> Both are false.Global values are implicitly initialised to 0, but local values have to be initialised by the system.
Explanation:-
Answer: Option B. -> Statement 2 is true, Statement 1 is false.An identifier can be declared many times must be defined just once.