Quote:
Originally Posted by
NoDoubtFilms 
I'm currently learning Java this semester then going to C next semester.
I understand just about every basic idea of Java (printing, DateFormats, DecimalFormats, if, else, switch, while, do-while, for, Arrays, Stacks, classes, methods, etc etc etc)
How easy will C be? Or is it a completely different world?
Coming from Java, it will be easier than learning C from scratch - I can tell you that much.
But in the world of C, you get to do most things yourself.
Quote:
Originally Posted by
Plan9 
You learning C or C++? C doesn't have strings nor classes. Where as C++ does.
Either one would be easier to learn once you know the basics of Java though as Java's syntax is very much C-like
+1
Quote:
Originally Posted by
Sisaroth 
There is no OOP in C. So no classes, private variables, objects.
Small command prompt programs are easier in C but once you want to use a GUI or send messsages over a network you have to write a lot more code to get this done.
the syntax is mostly the same, for/if/switchcase is all the same.
and like cdoublejj said, C doesn't run on a virtual machine so it doesn't has garbage collection.
if you do something like
char *array = malloc(32);
*array = malloc(32);
then you have 32 bytes allocated in your memory that you can't access and will stay there until you close the program. This is called a memory leak.
To solve this you have to release the memory before allocating more memory.
char *array = malloc(32);
free(array);
*array = malloc(32);
This very often leads to bugs because you freed something too early and then you tried reading data that was no longer allocated.
Those * are used to declarate pointers. Pointers are probably the hardest thing to get used to. In java everything is automaticly a pointer except the primitive types (int/char/double/etc). In C you have to write yourself if something is gonna be a pointer. After 3 years of learning C at school i still don't know when i have to use * or & or nothing. Luckily the compiler usually catches those errors.
typedefs solve the not knowing when to use a pointer problem/confusion.
Code:
typedef struct _my_type
{
int val1;
int val2;
} my_type, *p_my_type;
Then just use p_my_type everywhere in the code. No need for "*" or "&".
Also you can use realloc(). No need to free and then release to allocate memory at the same address.
Quote:
Originally Posted by
Makyl 
The thing is if you can learn one language its pretty easy to switch to another language you just have to read the syntax.
So it won't be hard. I myself learned Java then C++ then C(weird right?).
Bit more than just reading the syntax, but sure

Quote:
Originally Posted by
adridu59 
The fact that Java runs in a virtual machine isn't correlated with the presence of GC at all.
See, the D language has GC and it actually doesn't run in a VM.
Also, there is actually a GC algorithm for C:
Hans-Böhm, which works as a plugin and gets compiled with your code.
Not necessarily weird to start with Java since its a good starter language and the syntax is more easy-to-use.
But sure from a programming standpoint its a bit in reverse order.

The problem is that without the managed type of VM like in Java, the GC doesn't know enough about the program to be efficient enough so this is why you typically see the managed runtime and GC association. Garbage collection is just not something that is well suited to C or C++, though it is quite neat I must say. A virtual machine is different to a runtime - the runtime is where the GC lives.
Although arguably, the Java GC is pretty crap.
Edited by tompsonn - 11/2/12 at 12:55am