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
Explain virtual class?
Does std endl flush?
What do you mean by volatile and mutable keywords used in c++?
Describe the role of the c++ in the tradeoff of safety vs. Usability?
How much do c++ programmers make?
How do I write a c++ program?
Write about the role of c++ in the tradeoff of safety vs. Usability?
What c++ is used for?
What is main function in c++ with example?
How to access a variable of the structure?
What are the different types of polymorphism in c++?
How many types of modularization are there in c++?
What is the difference between a pointer and a link in c ++?
Draw a flow chart and write a program for the difference between the sum of elements with odd and even numbers. Two dimensional array.
What relational operators if statements in c++?