1. ## pointer

i have a basic program on pointer here i want to enter a number and get the value a and b the same. For example
input 10
output
a=10
b=10

and it doesnt work is that possible. because if i define int a=10 i will get
a=10
b=10

Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
int a , b;  // if i put int a = 10 this will let me get value a=10 and b=10
int  *ptr;
ptr = &a;
b = *ptr;
printf("enter a");
scanf("%i",&a);
printf("a = %d \n", a);
printf("b = %d \n", b); // i want to get 10 here

getch();
}

2. Whats your reason for wanting the pointer, are you just trying to learn them?

That is not going to work because you are assigning b to the value in a. If your print out the value of *ptr that will show the 10 you are looking for.

3. yea iam just trying to learn them. why is that when i printf("%i", *ptr) i= 10. i have asign b to ptr. b=*ptr. it should give me 10 for b. but it gives me a garbage value

4. The problem is that the *ptr has no values when you assign that to b.So it assigns the garbage value in the *ptr to b.After assigning that only you have get the value of a .Now that a's value will in the *ptr.

So you need to assign the pointer value to b after getting the input from the user.

Code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
main()
{
int a , b;  // if i put int a = 10 this will let me get value a=10 and b=10
int  *ptr;
ptr = &a;
// b = *ptr; // Wrong . Assigning the value in the pointer ( But a has no values so it gives the garbage values
printf("enter a");
scanf("%i",&a);
b = *ptr; // Correct . Assigning the value in the pointer ptr.( Because now the *ptr has the value of a ).
printf("a = %d \n", a);
printf("b = %d \n", b); // i want to get 10 here

getch();

}