100% Trying to swap no.s with & without using pointers
// Online C compiler to run C program online
#include <stdio.h>
int swapptr(int p, int q)
{
int tatkal;
printf("\n numbers before swapping in the called function: p=%d,q=%d",p,q);
tatkal=p;
p=q;
q=tatkal;
printf("\n numbers after swapping as printed in the function: p=%d,q=%d",p,q);
}
void main()
{
int a=4,b=5;
printf("\n numbers before swapping: a=%d,b=%d",a,b);
swapptr(a,b);
printf("\n values of a=%d,b=%d after returning back from called function",a,b);
}
తెరమీద
numbers before swapping: a=4,b=5#include <stdio.h>
int swapptr(int p, int q)
{
int tatkal;
printf("\n numbers before swapping in the called function: p=%d,q=%d",p,q);
tatkal=p;
p=q;
q=tatkal;
printf("\n numbers after swapping as printed in the function: p=%d,q=%d",p,q);
}
void main()
{
int a=4,b=5;
printf("\n numbers before swapping: a=%d,b=%d",a,b);
swapptr(a,b);
printf("\n values of a=%d,b=%d after returning back from called function",a,b);
}
తెరమీద
numbers before swapping in the called function: p=4,q=5
numbers after swapping as printed in the function: p=5,q=4
values of a=4,b=5 after returning back from called function
గమనిక a మరియు b విలువలు ఎందుకు మారలేదో ఆలోచించగలరు. ఇంతవరకు చేసినది కాల్ బై వాల్యూ పధ్ధతి
#include <stdio.h>
int swapptr(int *p, int *q)
{
int tatkal;
tatkal=*p;
*p=*q;
*q=tatkal;
}
void main()
{
int a=4,b=5;
printf("\n numbers before swapping: a=%d,b=%d",a,b);
swapptr(&a,&b);
printf("\n numbers after swapping: a=%d,b=%d",a,b);
}
తెరమీద
numbers before swapping: a=4,b=5
numbers after swapping: a=5,b=4
numbers after swapping: a=5,b=4
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.