write a function which accept two numbers from main() and
interchange them using pointers?

Answers were Sorted based on User's Feedback



write a function which accept two numbers from main() and interchange them using pointers?..

Answer / sarathi

#include<stdio.h>
main()
{
int *p,*q;
*p=10;
*q=20
void swap(int &p,int &q);
}
void swap(int *x,int *y);
{
int *tmp;
*tmp=*x;
*x=*y;
*y=*x;
printf("%d,%d",*x,*y);
}

Is This Answer Correct ?    5 Yes 4 No

write a function which accept two numbers from main() and interchange them using pointers?..

Answer / amritpal singh

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;

void swap(int *,int *); //Functioin Prototype
clrscr();
cout<<"\nEnter the number::\n";
cin>>a>>b;
cout<<"\nValues before INterchange are \na=<<" and \nb="<<b;

swap(&a,&b); //Functiion Calling

cout<<"\nValues after interchange\na=<<" and \nb="<<b;

getch();
}

void swap(int *a,int *b) //Function Defintioon
int temp;
temp=*a;
*a=*b;
*b=temp;

}




Thanks friends if any mistake pls coorect it by again urs
answer

Is This Answer Correct ?    2 Yes 2 No

write a function which accept two numbers from main() and interchange them using pointers?..

Answer / vignesh1988i

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,*ptr1,*ptr2,temp;
printf("enter the values ");
scanf("%d%d",&a,&b);
ptr1=&a;
ptr2=&b;
temp=(*ptr1);
*ptr=(*ptr2);
*ptr2=temp;
printf("\n now the values are a=%d b=%d ",a,b);
getch();
}


thank u

Is This Answer Correct ?    4 Yes 5 No

Post New Answer

More C Interview Questions

Give basis knowledge of web designing ...

0 Answers   HCL,


What is #line in c?

0 Answers  


What the different types of arrays in c?

0 Answers  


How do I determine whether a character is numeric, alphabetic, and so on?

0 Answers  


Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.

0 Answers  






swapping of two numbers without using third variable using AND and OR operators

2 Answers  


Write a main() program that calls this function at least 10 times. Try implementing this function in two different ways. First, use an external variable to store the count. Second, use a local variable. Which is more appropriate?

2 Answers  


There seem to be a few missing operators ..

0 Answers  


What is the difference between #include and #include 'file' ?

0 Answers  


Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......

0 Answers  


How would you print out the data in a binary tree, level by level, starting at the top?

6 Answers   Amazon, Microsoft,


Write a Program to print this triangle: * ** * **** * ****** * ******** * ********** use two nested loops.

12 Answers   MIT, TCS,


Categories