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 difference between new() and malloc() in c++?

0 Answers  


What do the keywords volatile and mean mutable?

0 Answers  


what is c++

0 Answers  


int f() { int I = 12; int &r = I; r += r / 4; int *p = &r; *p += r; return I; } Referring to the sample code above, what is the return value of the function "f()"? a) 12 b) 15 c) 24 d) 17 e) 30

2 Answers   AIG, Quark,


what are the iterator and generic algorithms.

0 Answers  






What are the steps in the development cycle?

0 Answers  


What are files in c++?

0 Answers  


What is guard code in c++?

0 Answers  


What is #include ctype h in c++?

0 Answers  


What is a template in c++?

0 Answers  


Given the following seqment of code containing a group of nested if instructions: y = 9; if ((x==3) || (x == 5)) y++; else if (x == 2) y *= 2; else if (x == ) y-= 7; else y = 8; if the value of x is 4 before the nested IFs are executed, what is the value of y after the nested IFs are executed?

0 Answers  


How is modularity introduced in C++?

0 Answers   TCS,


Categories