CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2013
    Posts
    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?

  2. #2
    Join Date
    Jul 2013
    Location
    USA
    Posts
    30

    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.

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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.

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Can I Study C++ to Learn C?

    Quote Originally Posted by GCDEF View Post
    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.

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Can I Study C++ to Learn C?

    there are very few for C alone.
    I suggest you have a look at these

    http://www.amazon.co.uk/Introduction...827083&sr=1-35

    http://www.amazon.co.uk/C-Programmin...827312&sr=1-70 (covers the essentials of c that you might get asked about)

    http://www.amazon.co.uk/Book-C-Progr...3827831&sr=1-1

    http://www.amazon.co.uk/C-Programmin...827897&sr=1-11

    http://www.amazon.co.uk/Ultimate-Con...827986&sr=1-18


    There's also some books that cover interview questions for c. Have a look at

    http://www.amazon.co.uk/Interview-Qu...3827986&sr=1-9

    http://www.amazon.co.uk/C-Interviews...827986&sr=1-14

    Or are there too many other major or minor differences that will screw me up on my C test?
    The quick answer is yes!
    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
  •  





Click Here to Expand Forum to Full Width

Featured