Objective
In this challenge, you will learn to implement the basic functionalities of pointers in C. A pointer in C is a way to share a memory address among different contexts (primarily functions). They are primarily used whenever a function needs to modify the content of a variable, of which it doesn't have ownership.
C - Hacker Rank Solution
#include <cstdio>
#include <cstdlib>
void update(int *a,int *b) {
int temp = *a;
*a = *a + *b;
*b = abs(temp - *b);
}
int main() {
int a, b;
int *pa = &a, *pb = &b;
scanf("%d %d", &a, &b);
update(pa, pb);
printf("%d\n%d", a, b);
return 0;
}
run time error bata rha hy code aapka
ReplyDeleteremove headerfile
DeleteWhat is meant by abs?
ReplyDeleteabsolute function which actually works as modulas
Deleteit's not getting executed compilation error de raha
ReplyDelete#include
Deletevoid sol(int *,int *);
int main(){
int a,b;
scanf("%d%d",&a,&b);
sol(&a,&b);
printf("%d\n%d",a+b,abs(a-b));
return 0;
}
void sol(int *x,int *y){
*x+*y;
abs(*x-*y);
}
ye wala kro execute hoga main khud se kiya hoo with the help of abs use
Delete#include
ReplyDelete#include
void update(int *a,int *b) //a=&a; b=&b; a,b is a pointer
/*
nt *a;
a=pa;
a=*a;
*a=a
int *b;
b=pb;
b=*b;
*b=b;
*/
{
int temp=*a;
*a =(*a+*b);
*b=int(abs(temp-*b));
}
int main() {
int a, b;
int *pa = &a, *pb = &b;
scanf("%d %d", &a, &b);
update(pa, pb);
printf("%d\n%d", a, b);
return 0;
}
Pointers in C – Hacker Rank Solution
ReplyDeletehttps://www.codeworld19.com/pointers-in-c-hacker-rank-solution/