I understand the concept of pointers and that we use them in functions to optimize the space we use.
What I don't get is the syntax when using them in functions.
Example 1:
void fun(int * a)//that means we declared a pointer to an integer type a
{
*a+=1;
}
fun(&b);//calling the function for int b=10;
Example 2:
void fun(int * a)//that means we declared a pointer to an integer type a
{
a+=1;
}
fun(&b);//calling the function for int b=10;
Question: which one is right and if they are both right what's the difference between the two?
EDIT After AKX's answer: Why do we in a linked list do this then? Shouldn't it be **head instead of *head in the body if we want to change the value of the object and not the adress of the pointer ( double-pointer in this case )??
void push(struct node **head, int data)
{
struct node* newnode = malloc(sizeof(struct node));
newnode->data = data;
newnode->next = *head;
}
push(&head,1);