Click to See Complete Forum and Search --> : how much of C should I learn in C++?
potatoCode
May 25th, 2008, 01:12 PM
Hello guys,
I read some articles on the net about some of the questions asked at job interviews.
I saw that many deal with the concepts that I'm not ware of, such as malloc and free.
The C++ book I've read so far did not mention them
and from what I gather, these are considered 'C' ways.
I also read Stroustrup's comment on how it is NOT necessary to know C in order to learn C++. But being here at the forum and doing some readings led me to believe I need to know C if I want to get a job as C++ programmer.
my question is how far back(or how deep) should I go in C ways of doing things?
This is a big concern for me because I feel like I do not have enough time to learn C and C++ at this point.
Thanks.
Lindley
May 25th, 2008, 02:13 PM
I think it's helpful to know a fair bit of C. Not so much for writing C++, as just to have a handle on the general concepts.
In the case of malloc/free, they're essentially the same as new/delete except that they have no concept of type. You allocate enough space for the type you want by using the sizeof() operator, and then just cast the memory to that type; it isn't initialized by a constructor as it would be with new.
ch0co
May 25th, 2008, 04:10 PM
Like Lindley said malloc/free is more like new/delete.
Details....
Heap memory is allocated using the new command followed by the type of object to allocate. For example, the following allocates a double variable off the heap.
double* child(void)
{
double* pdLocalVariable = new double;
return pdLocalVariable;
}
Although the variable pdLocalVariable goes out of scope when the function child() returns, the memory to which pdLocalVariable refers does not. A memory location returned by new does not go out of scope until it is explicitly returned to the heap using a delete command.
You should get a C++ job with that word for word. LOL.
TheCPUWizard
May 25th, 2008, 04:29 PM
JUST learn C++. Period. End of Discussion.
There is simply no poiont in learning things which are somewhere between inappropriat, wrong and plain illegal.
Once you have a good solid grasp on what is RIGHT to do in C++. Then start looking at other languages (such as "C") to see how they compare.
anwar4849
May 25th, 2008, 05:02 PM
JUST learn C++. Period. End of Discussion.
Just right. At this stage, you should concentrate on C++.
Actually the C is useful in some situations where you deal with some old code. There you generally find the C-specific functions and macros. That's why, in the interviews they asked for C-specifics. In my opinion, one should tell them (the interviewers) that every task can be obtained through C++ and there is no need to learn C. If any need arises during job (for reasons mentioned above), it will be simpler to deal with C-specific code by just referring the C-documentation.
Well, this is my opinion. May be interviewers have some other!!!
Thanks and best regards.
Anwar-ul-Haque
potatoCode
May 25th, 2008, 05:18 PM
Thanks guys!
@anwar4849: I see. Just curious, were you asked such a question when you tried out for your job?
thanks!
anwar4849
May 25th, 2008, 05:37 PM
@anwar4849: I see. Just curious, were you asked such a question when you tried out for your job?
Fortunate enough, I have not come up with such situation!!!
potatoCode
May 25th, 2008, 05:40 PM
Fortunate enough, I have not come up with such situation!!!
haha thanks!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.