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
How can we read/write Structures from/to data files?
what you know about c++?
How const int *ourpointer differs from int const *ourpointer?
Can we delete this pointer in c++?
What is the difference between object-oriented programming and procedural programming?
If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?
Describe the role of the c++ in the tradeoff of safety vs. Usability?
How new/delete differs from malloc()/free?
If a base class declares a function to be virtual, and a derived class does not use the term virtual when overriding that class, is it still virtual when inherited by a third-generation class?
What is called array?
Which software is used to run c++ program?
What data structure is fastest, on average, for retrieving data: a) Binary Tree b) Hash Table c) Stack
Why is it necessary to use a reference in the argument to the copy constructor?
What is the function to call to turn an ascii string into a long?
How a new operator differs from the operator new?