C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 7)
7.
Which of the following concept of oops allows compiler to insert arguments in a function call if it is not specified?
Call by value
Call by reference
Default arguments
Call by pointer
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
22 comments Page 1 of 3.

Piyush said:   6 years ago
Default parameters are the parameter used when not any other parameters are given.
(3)

Shalu said:   1 decade ago
In call by reference: We passes the value in calling time.

And call by reference: We pass the address in calling time.

Call by reference:

void swap(int &x, int &y)
{
..
....

}

swap(a, b);
call by pointer:
void swap(int *x, int *y)
{
...
..

}

swap(&a, &b);
(2)

Nikhil said:   1 decade ago
Pointer also carries a address n reference also carries a address then what is the difference between call by pointer and call by reference.
(1)

Amol said:   1 decade ago
Eg : Call by value.

include <stdio.h>

/* function declaration */
void swap(int x, int y);

int main ()
{
/* local variable definition */
int a = 100;
int b = 200;

printf("Before swap, value of a : %d\n", a );
printf("Before swap, value of b : %d\n", b );

/* calling a function to swap the values */
swap(a, b);

printf("After swap, value of a : %d\n", a );
printf("After swap, value of b : %d\n", b );

return 0;
}

Eg : call by reference & call by pointer one all the same.

#include <stdio.h>

/* function declaration */
void swap(int *x, int *y);

int main ()
{
/* local variable definition */
int a = 100;
int b = 200;

printf("Before swap, value of a : %d\n", a );
printf("Before swap, value of b : %d\n", b );

/* calling a function to swap the values.
* &a indicates pointer to a ie. address of variable a and
* &b indicates pointer to b ie. address of variable b.
*/
swap(&a, &b);

printf("After swap, value of a : %d\n", a );
printf("After swap, value of b : %d\n", b );

return 0;
}

Durgesh said:   9 years ago
It means that suppose you have not given any argument in the function call so by default it would take a value you already specified. This is called a function with default parameters.

Sakthi said:   1 decade ago
Hi @Amol.

What was the out put of the example program?

Nithyapriya said:   1 decade ago
If it specifies means what is the answer?

Guru said:   1 decade ago
What is mean by call by value, call by Reference and its difference?

Ash said:   1 decade ago
In call by value we directly pass value and in call by reference we pass address of that value.

Prashant Sable said:   1 decade ago
In call reference we pass address so actual parameter value get change.

In call by value formal parameter get copied into actual parameter so actual parameter doesn't change as both have different memory.


Post your comments here:

Your comments will be displayed after verification.