-
July 13th, 2013, 09:53 PM
#1
Can I Study C++ to Learn C?
I have to know C for a non-programming job interview--not expert level, but enough to look at code and know what's going on. I've studied C++ but it's been a while and I'm rusty, so I need to study. The problem is, all the books I really like are for C++; there are very few for C alone.
Would I be okay studying C++ books and just avoiding the OOP-related parts (classes, objects, inheritance, polymorphism, encapsulation, <iostream> vs. <stdio.h>)? Or are there too many other major or minor differences that will screw me up on my C test? Any other significant differences to avoid?
-
July 13th, 2013, 11:54 PM
#2
Re: Can I Study C++ to Learn C?
C is a subset of C++. Meaning C++ can compile and run most of C but C cannot compile and run C++ so if you are required to learn C I would not suggest it since very little of what you will learn will be useable. C is function driven whereas C++ is object driven.
-
July 14th, 2013, 02:18 AM
#3
Re: Can I Study C++ to Learn C?
Although most of C stuff can be used in C++, C is a different programming language.
It has different targets, C programmers are facing different problems, uses different approaches and a different programming "philosophy".
So, at a C interview you can expect more C-specific than C/C++ common problems.
Concluding: if your immediate target is to get a C programmer job, learn C language from dedicated C books.
-
July 14th, 2013, 07:38 AM
#4
Re: Can I Study C++ to Learn C?
On the other hand, anybody who is competent with C++ can look at C code and easily understand it.
-
July 14th, 2013, 12:33 PM
#5
Re: Can I Study C++ to Learn C?
Originally Posted by GCDEF
On the other hand, anybody who is competent with C++ can look at C code and easily understand it.
Yes, for the most part what GCDEF states is true. If the C code is within a function, then it more than likely can be understood by a C++ programmer.
However there are simple things that will throw a C++ programmer off, while a C programmer would more than likely know the answer. It all stems from C and C++ having different rules.
For example:
Code:
#include <stdio.h>
int main()
{
printf("%lf\n", sqrt(2.0));
}
If on a C test, you're asked "what does this output", a C++ programmer who wasn't aware of the rules of 'C' would say "1.414213" or something similar to that, and they would be wrong. A C programmer would say "cannot be determined because the behaviour is undefined", and the C programmer would be right. The C++ programmer would be even more confused that the answer is the latter after being told that the code above compiles and links successfully as a 'C' program.
Since header file inclusion/non-inclusion is ingrained in a C programmer's head as part of their experience, they know that sqrt() returns an int if the header (or correct prototype) is not used, when in fact sqrt() is a function that returns a double. Therefore the code is valid 'C', but it has undefined behaviour. So we don't know if the program crashes, prints "1.0000" or prints a totally bogus number not even remotely close to "1.4141213".
These types of questions can be used to flush out persons who falsely claim they are C programmers who have not really used the language (they are C++ programmers). Similarly, there are questions on C++ interviews that do the opposite, i.e. ask simple C++ questions to persons claiming to be C++ programmers who are really C programmers.
So the OP needs to be very careful. As Ovidiu mentioned, read 'C' books if the interview is about 'C', and not C++ books.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; July 14th, 2013 at 12:36 PM.
-
July 14th, 2013, 02:00 PM
#6
Re: Can I Study C++ to Learn C?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|