1. What does the following do:
void afunction(int *x)
{
x=new int;
*x=12;
}
int main()
{
int v=10;
afunction(&v);
cout<<v;
}
a) Outputs 12
b) Outputs 10
c) Outputs the address of v
Answers were Sorted based on User's Feedback
Answer / shakti singh khinchi
ANs: b. Output is 10.
bcoz in method afunction() allocates new memory to var x and
change its value after that, but tha actual variable doesn't
changes its location, thats why its remains same as it has
initialised by 10.
But if memory allocation by "new" has not ben done than it
will change the value as 12.
Is This Answer Correct ? | 4 Yes | 0 No |
structure that describe a hotel with name, address,rooms and number of rooms
How do I use arrays in c++?
What would happen on forgetting [], while deallocating an array through new?
What are structures and unions?
What is auto used for in c++?
What are the advantages of using typedef in a program?
What are Virtual Functions? How to implement virtual functions in "C" ?
In a class only declaration of the function is there but defintion is not there then what is that function?
How to change constant values?
What are virtual constructors/destructors?
Write a corrected statement in c++ so that the statement will work properly. if (x > 5); y = 2*x; else y += 3+x;
What is c++ map?