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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Define basic type of variable used for a different condition in C++?

670


Give 10 points of differences between C & C++.

627


Can a constructor be private?

584


Why c++ is created?

576


What is the basic difference between C and C++?

626






Is it possible for the objects to read and write themselves?

651


How the delete operator differs from the delete[]operator?

647


How do you define/declare constants in c++?

613


What is the difference between while and do while loop?

558


Is c++ faster than c?

596


What is c++ vb?

616


Why do we use constructor?

605


If you hear the cpu fan is running and the monitor power is still on, but you did not see anything show up in the monitor screen. What would you do to find out what is going wrong?

551


What is the most common mistake on c++ and oo projects?

525


Is c++ still in demand?

635