Given an example of passing arguments by references. In which rows compilation will fail?
void foo(int const* x, int* const y){
    int a;
   
    *x = 5; //1
    x = &a; //2
    *y = 5; //3
    y = &a; //4
    
}
int main()
{
    int x,y;
    foo(&x,&y);
}
Explanation
In order to properly answer this question, you can use a simple rule. It is necessary to read the classified function argument from right to left:
int const * x // x is a pointer to a const int (can not change the value of the variable to which the pointer points // 1)
int * const y // y is a constant pointer to int (can not change the value of the pointer // 4)

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes