Questions and Answers
- What is the output of this program?
#include <iostream>
using namespace std;
int StaticFunction(int)
{
int sum = 0;
sum = sum + 12;
return sum;
}
int main(void)
{
int num = 5, Res;
Res = StaticFunction(Res);
cout << Res << endl;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Even Though we passed the value, we didn’t caught to manipulate it, So it is printing as 12.
- What is the output of this program?
#include <iostream>
using namespace std;
int main(void)
{
const char *First = "Interview Mania";
cout << First << endl;
const char *Second = First;
cout << Second << endl;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
We are copying the values from one variable to other, So it will print two time Interview mania.
- What is the output of this program?
#include <iostream>
#include <new>
using namespace std;
int main ()
{
int k, num;
int * ptr;
num = 3;
ptr= new (nothrow) int[num];
if (ptr == 0)
cout << "Error: memory could not be allocated";
else
{
for (k=0; k{
ptr[num] = 7;
}
for (k = 0; k < num; k++)
cout << ptr[num] << " ";
delete[] ptr;
}
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
As we had given k value as 3, It will print the 7 for three times.
- What kind of error can arise when there is a problem with memory?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Segmentation fault
- When do we call that resource is leaked?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Resource is said to be leaked when it cannot be accessed by any means of standard mean.