0% found this document useful (0 votes)
79 views13 pages

Namespace (2 Files Merged Answers)

The document contains 10 coding questions related to namespaces in C++. Each question is multiple choice with 4 possible answers. The questions cover topics like defining namespaces, accessing variables and functions within namespaces, namespace scope, and using namespaces.

Uploaded by

Balu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views13 pages

Namespace (2 Files Merged Answers)

The document contains 10 coding questions related to namespaces in C++. Each question is multiple choice with 4 possible answers. The questions cover topics like defining namespaces, accessing variables and functions within namespaces, namespace scope, and using namespaces.

Uploaded by

Balu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

1. What will be the output of the following C++ code?

#include <iostream>
#include <string>
using namespace std;
namespace A{

int var = 10;


}
namespace B{
int cout = 5;
}
int main()
{
using namespace B;
cout<<A::var;
}
a) 10
b) 5
c) Error
d) 105

2. What will be the output of the following C++ code?


#include <iostream>
#include <string>
using namespace std;
namespace A{

int x = 50;
}
namespace B{
int x = 500;
}
int main()
{
using namespace B;
cout<<x;
}
a) 500
b) 50
c) Error
d) Wrong use of namespace

3.What will be the output of the following C++ code?


#include <iostream>
#include <string>
using namespace std;
namespace A{

int k = 123;
}
namespace B{
int k = 456;
}
int main()
{
int k = 20;
using namespace B;
cout<<k;
}
a) 123
b) 456
c) 20
d) Error

5. What will be the output of the following C++ code?


#include <iostream>
#include <string>
using namespace std;
namespace
{
int var = 10;
}
int main()
{
cout<<var;
}
a) 10
b) Error
c) Some garbage value
d) Nothing but program runs perfectly

6.What is the correct syntax of defining a namespace?


a) namespace name{}
b) Namespace name{};
c) namespace name[];
d) typedef namespace name{} NAME

7.How to print the value of the i variable inside namespace


B?

namespace A{
int var = 10;
namespace B{
int i = 15;
}
}
a) cout<<A::i;
b) cout<<B::i;
c) cout<<A::B::i;
d) cout<<i;

8.#include <iostream>
using namespace std;
namespace first
{
int x = 5;
int y = 10;
}
namespace second
{
double x = 3.1416;
double y = 2.7183;
}
int main ()
{
using first::x;
using second::y;
bool a, b;
a = x > y;
b = first::y < second::x;
cout << a << b;
return 0;
}

a) 1 1
b) 0 1
c) 0 0
d) 1 0

9.What will be the output of the following C++ code?


#include <iostream>
using namespace std;
namespace Box1
{
int a = 4;
}
namespace Box2
{
int a = 13;
}
int main ()
{
int a = 16;
Box1::a;
Box2::a;
cout << a;
return 0;
}
10. Which keyword is used to access the variable in the
namespace?
a) using
b) dynamic
c) const
d) static
1.What will be the output of the following C++ code?
#include <iostream>
using namespace std;
inline void f1(char b)
{
cout<<int(b)<<endl;
}
int main()
{
f1('a');
}
a. a b. 97 C. Error d. 65

2.#include <iostream>
using namespace std;
int fun(int x = 0, int y = 0, int z)
{ return (x + y + z); }
int main()
{
cout << fun(10);
}
a) Compiler error b) 0 C) 20 d) 10

3.
#include <iostream>
using namespace std;
int fun(int=0, int = 0);
int main()
{
cout << fun(5);
}
int fun(int x, int y)
{
return (x+y);
}

a) 5 b) Error C) 0 d) 10

4.#include<iostream>
using namespace std;
int sum(int a,int b)
{
return a+b;
}
float sum(int a,int b)
{
return a+b;
}
main()
{
cout<<sum(100,200)<<endl;
cout<<sum(100,200)<<endl;
}
a) 300 300 b) 100 200 c) Error d) none of these

5.Which of the following permits function overloading on c++?


a) type b)type & number of arguments
c).number of arguments d)number of objects

6.#include <iostream>
#include <iostream>
using namespace std;
int Add(int X, int Y, int Z)
{
return X + Y;
}
double Add(double X, double Y, double Z)
{
return X + Y;
}
int main()
{
cout << Add(5, 6);
cout << Add(5.5, 6.6);
}
a) compile time error b) 12.1 11 c) 11 12 d) 11 12.1

7.____ is a process to change the function name based on its


arguments.
a)Code Mangling b)name conversion c)Name Mangling
d)inline function

8.Name the function whose definition can be substituted at a place


where its function call is made _________
a) volatile function b) external function
c) inline function d) friend function

9.What will be the output of the following C code?


#include <stdio.h>
void inline f1(char b)
{
printf ("%d\n",b);
}
int main()
{
f1('a');
return 0;
}

a) Error b) a c) 97 d) 65

10.#include<iostream>
using namespace std;
int sum(int a,char b)
{
return a+b;
}
int sum(float a,double b)
{
return a+b;
}
main()
{
cout<<sum(100)<<endl;
cout<<sum(100.25f,22.5)<<endl;
}
a) 100 0 b) error c) garbage d) none of these

11.#include<iostream>
using namespace std;
int sum(int a,int b,int c=100);
main()
{
cout<<sum(10)<<endl;
cout<<sum(10,20,300)<<endl;
cout<<sum(50,100)<<endl;
}
int sum(int a,int b,int c)
{
return a+b+c;
}
a) 110 b) 330 c) 250 d) error

12.#include<iostream>
using namespace std;
int sum(int a,int b=100,int c);
main()
{
cout<<sum(10)<<endl;
cout<<sum(10,20,300)<<endl;
cout<<sum(50,100)<<endl;
}
int sum(int a,int b,int c)
{
return a+b+c;
}

a) 110 b) 330 c) 250 d) error

You might also like