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
Define the operators that can be used with a pointer.
What is the return value of the insertion operator?
What is an inclusion guard?
What are structs in c++?
Write a program to concatenate two strings.
Why the usage of pointers in C++ is not recommended ?
Why is c++ still used?
When do we run a shell in the unix system? How will you tell which shell you are running?
Explain one-definition rule (odr).
How to demonstrate the use of a variable?
Explain dangling pointer.
What are associate containers?
What is meant by iomanip in c++?
What is a set in c++?
Are c and c++ similar?