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

WHICH TYPE OF JOBS WE GET BY WRITING GROUPS .WHEN THE EXAMS CONDUCTED IS THIS EXAMS ARE CONDUCTED EVERY YEAR OR NOT.PLS TELL ME THE ANSWER

0 Answers  


Define the scope of static variables.

0 Answers  


write a program to find the given number is prime or not

2 Answers   Accenture, Vasutech,


When is an interface "good"?

1 Answers  


What is a wrapper function in c?

0 Answers  


what is the use of a array in c

6 Answers  


What is the meaning of typedef struct in c?

0 Answers  


How can I write a function analogous to scanf?

0 Answers  


coding for Fibonacci.?

1 Answers  


Explain the difference between malloc() and calloc() in c?

0 Answers  


Write a C program that computes the value ex by using the formula ex =1+x/1!+x2/2!+x3+3!+………….

1 Answers  


Explain the process of converting a Tree into a Binary Tree.

0 Answers   Ignou,


Categories