void swap(int a,int b)
{
a=a+b;
b=a-b;
a=a-b;
}
in this code always gives the same result for all case
Answers were Sorted based on User's Feedback
Answer / k.kavitha
NO,if the values of a&b are 10,20 respectively., Then
a=a+b becomes "a=30"
b=a-b becomes b=30-20 i.e., "b=10"
a=a-b gives a=30-10 i.e., "a=20"
| Is This Answer Correct ? | 20 Yes | 6 No |
Answer / moorthy
here a and b are local variable in function swap() where a
and b are swapped inside swap().so that swaping does not
affect variable in main().
| Is This Answer Correct ? | 12 Yes | 1 No |
Answer / prateek
Actually this code is for interchanging values of two
variables without using third variable
| Is This Answer Correct ? | 9 Yes | 1 No |
Answer / mangala pandi p
provided a+b is between the int minimum and int maximum
so the answer is no.
| Is This Answer Correct ? | 6 Yes | 5 No |
Answer / shouvik mitra
This code gives the interchange values of the two variables.But this code can also give the same result for the two variables when same numbers are inputted in both the variables, i.e. say a=5,b=5.
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / sayantan ghosh
This will never give a result as its call by value and even the values arnt printed in the function so the values in main will only be present
| Is This Answer Correct ? | 0 Yes | 0 No |
What is the use of pointers in C?
0 Answers Impetus, Motorola, Tavant Technologies, Virtusa,
Can U write a C-program to print the size of a data type without using the sizeof() operator? Explain how it works inside ?
What is page thrashing?
How many main () function we can have in a project?
what is linkage error when it occurs in c program
How can I find the modification date of a file?
Write a C program in Fibonacci series.
Tell us something about keyword 'auto'.
How to write in a function declaration and in function call in which the function has 'n' number of varible or arguments?
what is the output of the program and explain why?? #include<stdio.h> void main ( ) { int k=4,j=0: switch (k) { case 3; j=300; case 4: j=400: case 5: j=500; } printf (ā%d\nā,j); }
Just came across this question, felt worth sharing, so here it is I want you to make a C/C++ program that for any positive integer n will print all the positive integers from 1 up to it and then back again! Let's say n=5 I want the program to print: 1 2 3 4 5 4 3 2 1. Too easy you say? Okay then... You can ONLY USE: 1 for loop 1 printf/cout statement 2 integers( i and n) and as many operations you want. NO if statements, NO ternary operators, NO tables, NO pointers, NO functions!
What is the use of typedef in structure in c?