Vikash kumar
Vikash kumar

Reputation: 3

adding number in C using pointers, without taking variable?

Can we add two numbers using pointers but without using any variable like a,b? I mean, generally, we take two variables and store it in pointer... but is it possible to the numbers without taking variable or can we take pointer variable?

Upvotes: 0

Views: 86

Answers (1)

Ptit Xav
Ptit Xav

Reputation: 3219

Simple answer :

int *a = (int *)malloc(sizeof(int));
*a = 10;
int *b = (int *)malloc(sizeof(int));
*b = 20;
printf("%ld + %ld = %ld\n", *a , *b , *a + *b);

Upvotes: 2

Related Questions