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

Why use of template is better than a base class?

0 Answers  


What is cout flush?

0 Answers  


What is malloc in c++?

0 Answers  


How to get the current position of the file pointer?

0 Answers  


Can we define function inside main in c++?

0 Answers  






What is Memory Alignment?

2 Answers   TCS,


string somestring ; Which of the following choices will convert a standard C++ string object "somestring" to a C string? a) Copy.somestring () ; b) somestring.c_str () c) &somestring [1] d) std::cstring (somestring) e) (char *) somestring

1 Answers   Quark,


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 the output of: String a1 = "Hello"; String a2 = "world!"; String* s1 = &a2; String& s2 = a1; s1 = &a1; s2 = a2; std::cout << *s1 << " " << s2 << std::endl;

4 Answers   Lehman Brothers,


What header file is needed for exit(); a) stdlib.h b) conio.h c) dos.h

0 Answers  


What is the difference between reference and pointer?

0 Answers  


what are the types of Member Functions?

0 Answers  


Categories