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
Distinguish between new and malloc and delete and free().
Can we use this pointer in a class specific, operator-overloading function for new operator?
What is a storage class? Mention the storage classes in c++.
Why is it called c++?
Describe exception handling concept with an example?
Why #include is used?
What is prototype for that c string function?
What is heap sort in c++?
Where must the declaration of a friend function appear?
What is a flag in c++?
What operators can you overload in c++?
What is the keyword auto for?
What is the benefit of learning c++?
What is the full form of ios?
Which software is best for coding?