Home Answers Viewqa Java-Beginners turbo C Question 6.

 
 


Arijit Maji
turbo C Question 6.
2 Answer(s)      a year and 2 months ago
Posted in : Java Beginners

Explain call by value and call by reference with easy examples.

View Answers

February 28, 2012 at 10:55 AM


Call by value: In call by value method, the called function creates a new set of variables and copies the values of arguments into them. Example: Program showing Call by value method

void swap(int x, int y)
{ 
  int temp;
  temp = x;
  x = y;
  y = temp;
  printf("Swapped values are a = %d and b = %d", x, y);
}

void main()
{
  int a = 7, b = 4;
  swap(a, b);
  printf("Original values are a = %d and b = %d", a, b);
  printf("The values after swap are a = %d and b = %d", a, b);
}

Output: Original Values are a = 7 and b = 4 Swapped values are a = 4 and b = 7

The values after swap are a = 7 and b = 4 This happens because when function swap() is invoked, the values of a and b gets copied on to x and y. The function actually swaps x and y while the original variables a and b remains intact.

Call by reference: In call by reference method, instead of passing a value to the function being called a reference/pointer to the original variable is passed. Example: Program showing Call by reference method

void swap(int *x, int *y)
{
  int temp;
  temp = *x;
  *x = *y;
  *y = temp;
  printf("Swapped values are a = %d and b = %d", *x, *y);
}
void main()
{
  int a = 7, b = 4;
  swap(&a, &b);
  printf("Original values are a = %d and b = %d",a,b);
  printf("The values after swap are a = %d and b = %d",a,b);
}

Output: Original Values are a = 7 and b = 4 Swapped values are a = 4 and b = 7

The values after swap are a = 4 and b = 7 This happens because when function swap() is invoked, it creates a reference for the first incoming integer a in x and the second incoming integer b in y.


February 28, 2012 at 10:57 AM


For Java

Visit Here









Related Pages:
turbo C Question 6.
turbo C Question 6.  Explain call by value and call by reference with easy examples
turbo c pre-increment question
turbo c pre-increment question  Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times
turbo C Question 4.
turbo C Question 4.  Possible to print the following (Using for Loops): 1. * ** 2.* * ** * * * *   specify the format properly
turbo C Question 4.
turbo C Question 4.  Possible to print the following (Using for Loops): 1. * ** 2.* * ** * * * *   specify the format properly
turbo C Question 5.
turbo C Question 5.  is it possible to print "", 1st line (5 times),2nd line *(4 times),3rd line *(3 times),4th line *(2 times) & 5th line *(1 times) with Align Right. and also reverse order as 1,2,3,4,5 (but right aline
turbo C prog.
turbo C prog.  Is it possible to print ASCII value A to Z with out...;#include<stdio.h> #include<conio.h> void main() { for(char c='A';c<='Z';c++){ printf("\nASCII of %c is %i\n", a, a); } getch(); } C
how to get following answer in turbo c program
how to get following answer in turbo c program  input 123456789 output 1 2 3 4 5 6 7 8 9
turbo C prog.
turbo C prog.  Is is possible print ASCII value of a alphabets using turbo C prog
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)
Can u print in turbo C  Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)
Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print ++a in the same printf() command ten times)  Can u print in turbo c 9 8 7 6 5 4 3 2 1 0 using pre increment operator Only use print
Conditional Statement in Turbo C
Conditional Statement in Turbo C   Write a program that computes and assesses the tuition fee of the students in one trimester, based on the given mode of payment below: Plan (Key) Discount (-) or Interest (+) Cash (1) 10
Conditional Statement in Turbo C
Conditional Statement in Turbo C   Write a program that computes and assesses the tuition fee of the students in one trimester, based on the given mode of payment below: Plan (Key) Discount (-) or Interest (+) Cash (1) 10
turbo C prog. Q3
turbo C prog. Q3  What is the difference between if and ladder... } Example of ladder if: #include <stdio.h> main() { int a,b,c; printf("enter values for a,b,c"); scanf("%d%d%d",&a,&b,&c); if(a>
(ForPro) turbo C prog. Q4
(ForPro) turbo C prog. Q4  I need to learn some easy foxpro program.. for example sum,interchange, loop etc
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
C Program Question - Development process
C Program Question  How i can calulate sum of First digit and last digit of Five Numbers. e.g 12345 i want to calculate 1+5=6 how i can calculate in C Program?   Hi Friend, Try the following code
C# question
Create a Solution by name Bank with Classes Account.cs, SavingsAccount.cs and savingsTest.cs to Demonstrate Abstract Classes in C#  1st question... and savingsTest.cs to Demonstrate Abstract Classes in C
question for c++
question for c++   write Program to swap between two numbers if first number is greater than second number and total of two numbers greater than 10
C# question
C# question  Explain enumeration base types in C
C# question
C# question  In C#, string is a class or primitive type. Explain
C# question
C# question  Write a program in C# to create 3*4 matrix and show the sum of diagonal values
C# question
C# question  Write a program in C# to create 3*4 matrix and show the sum of diagonal values
C# question
C# question  How can we call method pass by reference in C
c question
c question  How to convert decimal numbers into binary digits without using pow function in c language
question for c++
question for c++   write Program to swap between two numbers if first number is greater than second number and total of two numbers greater than 10   Ã?¨Ã?±Ã?â? Ã?§Ã?â?¦Ã?¬ Ã?â??Ã?â?¦Ã?¨Ã?§Ã?¯Ã?â??Ã?© Ã?¨Ã
c++
c++  Write a console based C++ program that reads student information...;= 50) 5) Display the student name with the maximum GPA 6) Display the student name with the minimum GPA 7) Display Student GPAs as Letter Grades (A, B, C, D
c++
c++   Assume vector "x" of integers with values of 7, 3, 5, 8, 1, 9, 0, 4, 2, 6. Second, assume integer variables "a," "b" and "y" with values of 3, x.size()-5 and 0, respectively. Third, assume a for-loop header which: 3.1
C++Tutorials
; The world of programming evolves rapidly. Last year we used Turbo C++ v 4.5, today... C++ Tutorials              C++ Tutorial
C++ question 3
C++ question - add the two matrices and display the elements of resultant....   C sum of two matrices The given code allow the user to enter...; #include <conio.h> void main() { int m, n, c, d, first[10][10], second[10
C/C++ - Development process
C/C++  I need the code for playing the backgammon game using C/C++.Im using turbo C. I`ve already design the board.I badly need the code for playing this game
C++ Question 2
C++ Triangle and Rectangle - calculate area of Triangle and rectangle using data members from base class  2.create class. Shape accepts two values (Data Type: Double). Create two derived classes Triangle and Rectangle ; calculate
C interview questions
? a. 5 b. 6 c. 10 d. 11 e. 12 /question number 2/ With every use of a memory........ TECHNICAL - C /question number 1/ Code: int z,x=5,y=-10,a=4,b=2... = ELLO c. y = LLO d. y = LO e. x = O /question number 5/ Code: struct node
C interview questions
? a. 5 b. 6 c. 10 d. 11 e. 12 /question number 2/ With every use of a memory........ TECHNICAL - C /question number 1/ Code: int z,x=5,y=-10,a=4,b=2... = ELLO c. y = LLO d. y = LO e. x = O /question number 5/ Code: struct node
Question?
Question?  My question is how to: Add a menu bar to the program... { final int NUM = 31; final int PICKS = 6; FlowLayout flow = new... implements ItemListener { final int NUM = 31; final int PICKS = 6
Java Programming: Chapter 6 Quiz
) g.drawLine(i,10,j,60); } Question 6: Suppose... Quiz Questions For Chapter 6 THIS PAGE CONTAINS A SAMPLE quiz on material from Chapter 6 of this on-line Java textbook. You should be able
C/C++ Programming Books
;   Visual C++ 6 Unleashed Visual C++ 6 Unleashed provides comprehensive coverage of the core topics for Visual C++ 6 programming. This book skips the beginning level material and jumps
java bits 6 - Java Interview Questions
java bits 6  Given: ? d is a valid, non-null Date object ? df is a valid, non-null DateFormat object set to the current locale What outputs...(loc.getDisplayCountry() + ? ? + df.format(d)); C. Locale bc = Locale.getLocale
C Help - Development process
C Help  Dear sir, I'm developing a program in c using TURBO-C, i want that when my program runs the console window(cmd) should be hidden. program should run in task manager. thnx
c program
c program  plz send me program for this. write a program to print the following code? (in c language) 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 2 3 4 5 6 7 8 9 10
C program
C program  hi, here is my question: Create a structure to specify data on students given below: Roll number, Name,Department, Course, Year... a function to print names of all students who joined in a particular year. (c
c program
c program  plz send me program for this. write a program to print the following code? 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 2 3 4 5 6 7 8 9 10 11 12 3 4
c# (ado.net)
c# (ado.net)   i am preparing a 180 query questions. how to make a groupbox that include 3 radio buttons named (YES, NO, CANCEL)when i select YES... selecting one of the 3 buttons then it goes to the next query question
Java Programming: Chapter 6 Quiz Answers
is the picture: Question 6: Suppose you would like an applet... Sample Quiz Answers For Chapter 6 THIS PAGE CONTAINS SAMPLE ANSWERS to the Quiz on Chapter 6 of this on-line Java textbook. Note
Java interview question
: Problem: 1) You have a bunch of log files in: C:\CloudShareCodeChallenge\Challenge Sample data with expected results (below) in C:\CloudShareCodeChallenge...-explanatory. All the clues/notes above are important :) 6) Your tasks: Provide
program in c
2 7 4 6 Sum is: 23 Average is: 4.5 Smallest: 1 Largest 7
c++ - AOP
c++  hi friends,i got this question and i need u help. "Two subjects namely computer aided design(subject1)and computer programming(subject2)are to be assessed.a set of marks are available for a class of students.For each
Guide to download and install Tomcat 6
Guide to download and install Tomcat 6   ... the process to downloading and installing Tomcat 6 on your computer system... installation directory.  set JAVA_HOME=C:\Program Files\Java\jdk1.6
C++ - XML
C++  C++ function declarations for : 1) isEmptyList():boolean... whether the insertion was successful 6) compareList(in firstItem:ListItemType...) C++ function definitions, using the operations declared above: 7

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.