Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm a C# developer now. As such, I'm familiar with classes and OOP concepts.

An upcoming project may require the software to be written in ANSI C.

If I were to take a C++ training course, how much of that would apply to C?

In other words, when I get the training for pointers, memory allocation, etc in C++, will that be the same in C?

Or should I try to find a course in ANSI C instead?
Posted
Comments
Sergey Alexandrovich Kryukov 16-Apr-14 12:41pm    
Why not just reading on this topic?
—SA

Please see: http://en.wikipedia.org/wiki/Compatibility_of_C_and_C%2B%2B[^].

If you learned C++ well, you can consider that you already know C, after learning the scope of C and some C peculiarities, like those listed in the section "Constructs that behave differently in C and C++" of the article referenced above.

For more information: http://bit.ly/1j0Pe4c[^].

—SA
 
Share this answer
 
If your project is restricted to ANSI C, knowing C++ won't help you unless you also know where C and C++ overlap. The C compiler will complain for things otherwise valid in C++.

Some of the more obvious differences:

1. no bool (depends on compiler)
2. no classes
3. no member functions
4. local variables must be declared at the start of function scope.

Take the for loop, for example.

This is okay in C++:

C++
for (int i = 0; i < 10; i++)


ANSI C expects this:

C++
int i;
for (i = 0; i < 10; i++)


You might be better off learning C first. There's less to learn. Everything will carry forward when you learn C++ - and you'll know the differences.
 
Share this answer
 
Comments
Legor 28-Apr-14 3:46am    
Using new C Standards this is also allowed in ANSI C:
for (int i = 0; i < 10; i++)

This was introduced with C99.

Only in C90 you have to declare the loop variable before the loop.
[no name] 2-May-14 11:10am    
That's a very good point!

http://stackoverflow.com/questions/24881/how-do-i-fix-for-loop-initial-declaration-used-outside-c99-mode-gcc-error
C++ is a superset of the C language. Originally Bjarne Stroustrup created C++ as a way to add classes to C. And as such, C++ was born.

So if you know C++ you know C.
 
Share this answer
 
Comments
Matt T Heffron 25-Apr-14 13:33pm    
Syntactically it is true: C++ is a superset of C.
Except C++ has classes and inheritance and C does not.
C++ uses (prefers) new and delete for memory management where C requires malloc and free.
C++ has standard libraries for strings, vectors, etc., where in C you're on your own.
So you *will* have to think differently to code in C vs. C++.

*In C notation, C++ is a post-increment, so it implies: improve the language, but use it the way it was before! :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900