Is it appropriate to attend a class one is not registered for? Is it appropriate for a student to attend a class s/he is not registered for? 

I am a CS student and I am almost done with my degree, but there are some very interesting electives that I will not get to take and I would love to simply attend those courses any way. 

Is this inappropriate to do? Should I ask the professor's permission first? 

I am not sure what my school's policy on the matter is, since I could not find a single source on the topic online from them.
In the American system, this is called "auditing" a course. Auditing means that you are attending the class but are technically only listening (auditing => auditory => listening) to the material and not sitting for exams or handing in homework assignments. You can audit a course formally (which often means that this is listed on your transcript) or informally in which you just sit in on the lectures/discussions. For the former/formal, see your local university guidelines. This answer deals with the latter.

Permission of the instructor in all but the larger lectures is always a good idea unless your university has an open classroom policy (as with many European universities). The instructor may have different rules. For example:


In larger lectures, I do not mind auditors (of any ilk) in lecture but they may not attend discussion sections since those are for the paying students.
I allow graduate students to audit my graduate seminars but with three rules: a) They must attend all of the sessions; b) they must do all of the readings; c) they must not be a 'dead body' but must participate in the seminar discussion.


Note that the university itself may have rules on auditing which the faculty member may ignore (for example, I do not mind if local community residents audit my lectures even if they are not registered as auditors through the university).

This is different from PASS/FAIL (also known as CREDIT/D/FAIL) which is another alternative in which you take the class but are allowed a lower level of participation.