Well, here goes:
First, yes C++ has literally inherited the syntax from C in this sort of case. If it is a base type ( int, short, float, char, etc.), it exists in much the same way in C++ as far as this goes with syntax of declarations, assignments, comparisons and such. There is one exception to that, location, location, location. In C ( not C99, just C ), you must declare all of your variables at the start of the file globally, at the start of the function that they are to have scope and lifetime in or not at all. All declarations for variables with base types or compound types must be at the beginning so that the compiler has information about sizes and names to use for errors and warnings. C++ and C99 both allow declaration at the place they are to be used at in the code.
Second, no, an integer variable in a C++ compiler doesn't work internally the *EXACT* same way as it does in a C compiler. These few special cases can be ignored for the most part, though it is sometimes necessary in odd circumstances to know of them. Internally, since C++ is object oriented and works with the assumption that *EVERYTHING* has to work one way for *EVERYTHING ELSE* so that nothing is treated differently and causes an internal snafu, the compiler in a sense treats integers and other base types as objects. Whew, that was a mouth full. What it means is that *ALL* data types have a couple of things under C++'s hood that they don't in C. They are a default copy constructor (C base types have no 'idea' that they are being 'constructed'!) and RTTI type ID information ( C base types don't have a clue what they are and 'don't care', meaning they don't know anything except size of memory ).
More good information on this can be had by reading "Thinking in C++" by Bruce Eckel. The URL below allows you access to download it free.
2006-10-03 05:49:20
·
answer #1
·
answered by Anonymous
·
1⤊
0⤋
Yes, C++ has "literally inherited this feature from C".
C++ syntax is a superset of C syntax. That is, any legal C statement is a legal C++ statement. However, there are lots of C++ statements that are not legal C. In fact, the first C++ compiler generated C code which was then compiled to native instructions.
However, an int is not an object in C++. It is a primitive type, and does not have any methods. This is also true in Java, another object oriented language with a C-like syntax.
2006-10-02 14:01:03
·
answer #2
·
answered by arbeit 4
·
1⤊
0⤋
yes, C++ has inherited everything from C, and u can literally do anything in C++ which u can do in C.
C++ is an increment over C, so it adds some advanced features.
Like in c u have to declare all the variables at the top of te main() or if they r globle then ryt after the file preprocessors declaration, while in C++ variables can be declaired anywhere, provided that they should be declaired b4 using them.
eg. u can have this in C++ but not in C.. for(int i;....;....)
2006-09-27 21:12:18
·
answer #3
·
answered by Digitally Й!Й 3
·
0⤊
0⤋
No, there isn't any difference between variable declaration in C and C++
Yes, C++ has literally inherited this feature from C.
2006-09-27 19:35:02
·
answer #4
·
answered by iyiogrenci 6
·
0⤊
0⤋
Syntactically, no. Both languates use the construct:
"int i;"
to declare an integer "i" for use in a module.
However, theoretically, an "int" in C is just an int. In C++ it's an "OBJECT."
2006-09-27 19:28:42
·
answer #5
·
answered by jbtascam 5
·
0⤊
1⤋