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
What are enumerations?
What is a list c++?
Who invented turbo c++?
Explain how overloading takes place in c++?
In which header file does one find isalpha() a) conio.h b) stdio.h c) ctype.h
Write about c++ storage classes?
What does return 0 do in c++?
Why we use #include conio h in c++?
What are static member functions?
What is token c++?
What is pointer -to-members in C++? Give their syntax?
How does list r; differs from list r();?
On throwing an exception by the animal constructor in p = new animalq, can memory leak occur?
What are the uses of typedef in a program?
What is difference between rand () and srand ()?