Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

C++ programming practical question 7

  Shared By: Adah Miller    Date: Jan 24    Category: C++ Programming    Views: 70

Answer:

const int size = 5;
void print(int *ptr)
{
cout<<ptr[0];
}

void print(int ptr[size])
{
cout<<ptr[0];
}

void main()
{
int a[size] = {1,2,3,4,5};
int *b = new int(size);
print(a);
print(b);
}


Answer:
Compiler Error : function 'void print(int *)' already has a body


Explanation:
Arrays cannot be passed to functions, only pointers (for arrays, base addresses)
can be passed. So the arguments int *ptr and int prt[size] have no difference
as function arguments. In other words, both the functoins have the same signature and
so cannot be overloaded.

Share: 
 

Didn't find what you were looking for? Find more on C++ programming practical question 7 Or get search suggestion and latest updates.


Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: