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

Answers were Sorted based on User's Feedback



1. What does the following do: void afunction(int *x) { x=new int; *x=12; } int main(..

Answer / guest

Ten(10) is the out put

Is This Answer Correct ?    9 Yes 0 No

1. What does the following do: void afunction(int *x) { x=new int; *x=12; } int main(..

Answer / ranjeet garodia

b is correct

Is This Answer Correct ?    8 Yes 0 No

1. What does the following do: void afunction(int *x) { x=new int; *x=12; } int main(..

Answer / 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

1. What does the following do: void afunction(int *x) { x=new int; *x=12; } int main(..

Answer / arun pateel

Answer is b

Is This Answer Correct ?    1 Yes 0 No

1. What does the following do: void afunction(int *x) { x=new int; *x=12; } int main(..

Answer / manish podiyal

C): outputs the address of v.

Is This Answer Correct ?    1 Yes 8 No

Post New Answer

More C++ General Interview Questions

Explain the benefits of proper inheritance.

0 Answers  


Mention the storage classes in c++.

0 Answers  


Is there a c++ certification?

0 Answers  


How can an improvement in the quality of software be done by try/catch/throw?

0 Answers  


What is virtual methods?

0 Answers  


What are associate containers?

0 Answers  


What are the uses of pointers?

0 Answers  


Of the numbers 12 23 9 28 which would be at the top of a properly implemented maxheap a) 28 b) 9 c) Any of them could be

0 Answers  


what is pre-processor in C++?

0 Answers  


What is a breakpoint?

0 Answers  


What are the sizes and ranges of the basic c++ data types?

0 Answers  


Shall we use 'free' to free memory assigned by new, What are the further consequences??

5 Answers   Symphony,


Categories