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

When should structures be passed by values or by references?

0 Answers   Adobe,


If fflush wont work, what can I use to flush input?

0 Answers  


c program to compute AREA under integral

0 Answers   Infosys,


How can I implement opaque (abstract) data types in C? What's the difference between these two declarations? struct x1 { ... }; typedef struct { ... } x2;

2 Answers  


#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }

0 Answers   Wilco,


how memory store byte

4 Answers   Huawei,


how to make program without <> in libray.

0 Answers  


What is the difference between struct and union in C?

1 Answers  


When should the register modifier be used? Does it really help?

0 Answers  


Difference between Class and Struct.

13 Answers   Ericsson, Motorola, Wipro,


How to avoid structure padding in C?

8 Answers   Tech Mahindra,


Write c-code for 5+55+555+5555+55555+555555+5555555. Output will be it's answer...

4 Answers   TCS,


Categories