0

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?

3
  • 1
    Please specify the language and any code that you may have tried. Commented Feb 18, 2021 at 15:19
  • The values are actually stored in memory. The variables are names given to that memory. Pointers are variables that store addresses of those memory, usually in the case of dynamic memory allocation Commented Feb 18, 2021 at 15:23
  • actually i'm trying it in C language Commented Feb 21, 2021 at 15:55

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.