scanf("%d%d",a,b); tells scanf to read numerals from input and write their values to the places in memory where a and b point. But a and b do not properly point to anywhere because you did not initialize them. Neither their definition in int *a,*b,*add; nor their use in scanf sets a value for where they point to.
To make a, b, or add point to an actual int object, you must define or allocate an int object and then assign its address to a, b, or add.
For example, you can use:
int x, y, z;
int *a = x, *b = y, *add = z;
Or:
int *a, *b, *add;
a = malloc(sizeof *a);
b = malloc(sizeof *b);
add = malloc(sizeof *add);
if (!a || !b || !c)
{
fprintf(stderr, "Error, memory allocation failed.\n");
exit(EXIT_FAILURE); // Include <stdlib.h> for this.
}
If your code “works” in Turbo C++, it may be because the uninitialized a, b, and add take on values that happen to be in memory that happened to point to usable memory. This is not reliable behavior, and it could easily break if any changes are made to the program. Always initialize pointers and other objects before you use them.
When you are done using memory allocated with malloc, you should generally release it, which you can do with free:
free(add);
free(b);
free(a);
scanfwants pointers to an allocated space: useint a = malloc(sizeof *a);beforescanf