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 2 of 3.

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;
}

Revathi said:   1 decade ago
Give an example program for each call by value, call by reference, call by pointer.

Lachu said:   1 decade ago
The difference between the call by value and call by reference are :The original value is not affected in call by value. That is only copies the value. Original value is affected in call by reference. That is value is changed after calling it.

Devyashish Mayank said:   1 decade ago
For call by value it means we pass a certain value (a no. ) to the function as parameter. While in case of call by pointer it means that we pass a pointer as an argument to it which points to certain address. In case of call by reference we simply provide an address to the function as an argument or parameter to get the desired result.

Venkatareddy said:   1 decade ago
Difference between call by value & call by pointer & call by reference perfect answer give me?

Vish said:   1 decade ago
Actually I made the guess by thinking that call by reference and call by pointer is one and the same thing and concept of call by value is clear from which we can easily conclude that answer will be the option 'C'.

Saroj said:   1 decade ago
Call by reference means call by address thats it.

Harish said:   1 decade ago
Difference b/w call by reference and call by pointer ?

Sri said:   1 decade ago
Actuvally primitive data types are used call by valu where as objects are passed by call by reference. About default arguments if we are not give the arguments compiler set the default arguments.

Jaydeep Pandya said:   1 decade ago
But how to apply default parameters.


Post your comments here:

Your comments will be displayed after verification.