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

structure that describe a hotel with name, address,rooms and number of rooms

2 Answers  


How do I use arrays in c++?

0 Answers  


What would happen on forgetting [], while deallocating an array through new?

0 Answers  


What are structures and unions?

0 Answers  


What is auto used for in c++?

0 Answers  






What are the advantages of using typedef in a program?

0 Answers  


What are Virtual Functions? How to implement virtual functions in "C" ?

3 Answers  


In a class only declaration of the function is there but defintion is not there then what is that function?

5 Answers   Hughes,


How to change constant values?

6 Answers   Huawei, Symphony,


What are virtual constructors/destructors?

0 Answers  


Write a corrected statement in c++ so that the statement will work properly. if (x > 5); y = 2*x; else y += 3+x;

1 Answers  


What is c++ map?

0 Answers  


Categories