I\'ve been learning C at Varsity for just shy of 2months now, and next year we\'ll be moving on to C++.
Are there any habits I should get into with my C programmin
You're shifting to C++ means that you felt you needed classes, or better libraries. Thats what I feel. I am also learning better features of C++, with my C background. Uptil now, I have had a look at vectors mainly [apart from classes and templates].
I feel the languages are too similiar to
think of them completely separately.
C++ programs are totally different. you had better spend your time learning C++ than working on C elements trying to improve them for C++.
For example even the simple 'Hello World' program, differs considerably:
C:
#include <stdio.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}
C++:
#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
}
(Examples from here).
As 'printf' is a function whereas 'cout' is not a function but an instance of an ostream class.
Further reading: iostream.
Function pointers. Google first hit.
If you can get hold of it I'd recommend the first 3 chapters of The C++ Programming Language by the creator of C++ Bjarne Stroustrup.
In particular the "Notes to the reader" and "Tour of C++" will give you a good understanding of where/how C++ differs from C and to focus your further learning. Of course the whole book is useful to have nearby when working with C++.
Interestingly for your situation, in chapter 1, Bjarne actually says
"in the continuing debate on whether one needs to learn C before C++, I am firmly convinced that it is best to go directly to C++".
Of course he would, wouldn't he, but if you accept his reasoning you would be best to jump straight in to C++ as soon as possible.
C++ is object orientated, C is not. So common things like keeping pointer code clean and comment's on functions/methods and understand how to not get infinite preprocessor loops using #IFDEFs.
However the object orientated approach can often be nicer to actually code thinking about objects. So you need to think about the new features difference.
The style of programing in C and C++ are entirely different. C++ is object oriented programing where as C is procedure oriented programing. C++ programing is the best in simulating real-world problems using classes/objects. But, basic concepts like pointers, structures, operators, casting operators, data handling are the same in both.. Sturctures and Classes are similar concept but not exactly.. so you can concentrate on programing using structures, pointers, operators and Memory managment while you are learning in 'C'