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
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 |
Write a Program for find and replace a character in a string.
What are the various access specifiers in c++?
Why is c++ not purely object oriented?
What is a parameterized type?
What programming language should I learn first?
What are the advantages of inheritance in c++?
What is operators in c++?
Which software is used for c++ programming?
What are the uses of c++ in the real world?
Write a C++ Program to Multiply two Numbers
Write a program and call it sortcheck.cpp which receives 10 numbers from input and checks whether these numbers are in ascending order or not. You are not allowed to use arrays. You should not define more than three variables
What is the use of bit fields in structure declaration?