C and C++ interview questions
I have a job interview in two days, and I just remembered some questions from my previous interview. The interviewer asked me what are some pitfalls of C and C++? And what are the advantage and disadvantages of using C and/or C++, compared to other languages (including C/C++). I answered them poorly last time, so help me out. I think I know the advantages of C++ (like OOP, templates, etc..), so don''t include them in your replies. Thank you, dudes!
Well, first off, let''s start with C.
C is a compiled language. Which means that it has better performance than interpreted languages, and most likely more access to the system than any interpreted language. On the down side the compile-link cycle of development makes manual modification of code on the run impossible, and it makes the language less suited towards rapid prototyping.
C is a high-low level language. Which means that the assembly code (and consequently machine code) generated by a given segment of C code is easy to determine. There are very few hidden costs associated with C. This leads to better performance, and better access to hardware features. On the downside it makes it easier to shoot yourself in the foot.
C is a loosely typed language with structural equivalence based on structure names. The latter implies that two structures with the exact same internal representation are distinct types. The former implies that the compiler really doesn''t care if you ask nicely. The combination of the two also leads to the easy to shoot yourself in the foot phenomenon. In comparison strongly typed languages can often prevent common programming errors, that a C compiler will blithly let slip by.
C is a block structured language without nested function declarations. On the whole nested function declarations are a pain, but the use of access links often can improve the performance over the alternative of passing the local variables of the parent function by reference or address. There isn''t much more commentary here because block structured languages are the norm.
C is also a procedural language (as compared to a functional language). This makes it easy to describe what the processor is doing at any given point in time. However, this also implies that not all data types are first class values.
The C memory model is nice blend of stack allocation, heap allocation and pointers every which way. This again contributes to that shoot yourself in the foot syndrome, while at the same time making C very flexible. Compare to Java which has automatic memory deallocation or LISP which has automatic memory management.
Now consider C++. C++ really isn''t that much different than C. The compiler is a little stricter with type checking and there is the syntactic sugar known as classes. These combine to make it harder to shoot yourself in the foot. But when you do manage it, you inflict a lot more damage.
C is a compiled language. Which means that it has better performance than interpreted languages, and most likely more access to the system than any interpreted language. On the down side the compile-link cycle of development makes manual modification of code on the run impossible, and it makes the language less suited towards rapid prototyping.
C is a high-low level language. Which means that the assembly code (and consequently machine code) generated by a given segment of C code is easy to determine. There are very few hidden costs associated with C. This leads to better performance, and better access to hardware features. On the downside it makes it easier to shoot yourself in the foot.
C is a loosely typed language with structural equivalence based on structure names. The latter implies that two structures with the exact same internal representation are distinct types. The former implies that the compiler really doesn''t care if you ask nicely. The combination of the two also leads to the easy to shoot yourself in the foot phenomenon. In comparison strongly typed languages can often prevent common programming errors, that a C compiler will blithly let slip by.
C is a block structured language without nested function declarations. On the whole nested function declarations are a pain, but the use of access links often can improve the performance over the alternative of passing the local variables of the parent function by reference or address. There isn''t much more commentary here because block structured languages are the norm.
C is also a procedural language (as compared to a functional language). This makes it easy to describe what the processor is doing at any given point in time. However, this also implies that not all data types are first class values.
The C memory model is nice blend of stack allocation, heap allocation and pointers every which way. This again contributes to that shoot yourself in the foot syndrome, while at the same time making C very flexible. Compare to Java which has automatic memory deallocation or LISP which has automatic memory management.
Now consider C++. C++ really isn''t that much different than C. The compiler is a little stricter with type checking and there is the syntactic sugar known as classes. These combine to make it harder to shoot yourself in the foot. But when you do manage it, you inflict a lot more damage.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement