it still prints me the printf function, although the condition is not satisfied.
I can avoid this by creating an else goto noterror. But what if I need a lot of goto, does it mean I need to also create a gotonoterror (under else) for each part?
why does it keeps going to goto, although the condition is not satisfied for the above code? any other way to avoid this?

The goto allows you to jump to a tagged location in your code. If you set up a tag ( error: in your case) then goto error; moves execution directly to that location. Nothing prevents that location from being in some other execution path as well.

If you've got some conditional execution path that you'd like to add use the if (condition) construct to control that: place the code within the scope of the if statement. There are limited instances where goto can not be replaced by some other logic. It is best to avoid goto in general until you come across one of these instances.

The goto allows you to jump to a tagged location in your code. If you set up a tag ( error: in your case) then goto error; moves execution directly to that location. Nothing prevents that location from being in some other execution path as well.

If you've got some conditional execution path that you'd like to add use the if (condition) construct to control that: place the code within the scope of the if statement. There are limited instances where goto can not be replaced by some other logic. It is best to avoid goto in general until you come across one of these instances.

yes, I understand that.
but I am still unclear about the if condition, as in my code, I put the goto under if condition (if a!=2, print error).
However, the goto statement is still executed, although it contradict the if statement. As what I understand from your explanation, I am doing the right thing (or?)