6)swap(int x,y)
{
int temp;
temp=x;
x=y;
y=temp;
}
main()
{
int x=2;y=3;
swap(x,y);
}
after calling swap ,what are yhe values x&y?

Answers were Sorted based on User's Feedback



6)swap(int x,y) { int temp; temp=x; x=y; y=temp; } main() { int x=2;y=3; swap(x,y); } af..

Answer / selloorhari

After calling the function swap(), the values of x,y will be
the same.

i.e. x = 2, y = 3.

The scope of the variables x,y,temp in the swap() function
lies inside the function swap() itself. So there will not be
any change in the values of x,y in the main() function..

Is This Answer Correct ?    17 Yes 0 No

6)swap(int x,y) { int temp; temp=x; x=y; y=temp; } main() { int x=2;y=3; swap(x,y); } af..

Answer / shruti

the values will be x =2 and y = 3.

the variables x and y declared in main() are local to main.

whereas

the variables x and y declared in swap() are local to swap..

the change in the value of the variables in either
function will have zero effect on the other function.

Hence the value remains teh same.

Is This Answer Correct ?    16 Yes 1 No

6)swap(int x,y) { int temp; temp=x; x=y; y=temp; } main() { int x=2;y=3; swap(x,y); } af..

Answer / shankar

Value remain same hare....I.E :- X=2,y=3.Because here rules of call by value is applied. If we use call by reference the only value is changed .

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Interview Questions

What is c++ used for today?

0 Answers  


define c

6 Answers   HCL, TCS,


What are the Advantages of using macro

0 Answers  


Can you mix old-style and new-style function syntax?

0 Answers  


Are there namespaces in c?

0 Answers  






How is = symbol different from == symbol in c programming?

0 Answers  


What is restrict keyword in c?

0 Answers  


Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record

0 Answers   Wipro,


What is the default value of local and global variables in c?

0 Answers  


What is c definition?

0 Answers  


How does struct work in c?

0 Answers  


Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

0 Answers  


Categories