Hardware Reference
In-Depth Information
putchar(pc);
}
fclose(fq);
fclose(fp);
exit();
return(0);
}
Difference between
C and C ++
As well as enhancements to the basic language, C ++ provides object-oriented
extensions to C required for modern 'visual' environments. In effect, C ++
is a superset of ANSI C and C programs will normally compile without any
problems in a C ++ environment. C ++ also attempts to resolve some of the
problems with the basic C language.
Differences between C and C ++ are usually apparent from a quick
examination of the code. For example, a comment in C would look like this:
/* A comment in C */
or, spanning several lines:
/* A comment
in C
*/
Comments in C ++ can use either of the following formats (the second example
is an in-line comment and the // designates the entire line as a comment):
/* A comment in C++ */
or, spanning several lines:
/* A comment
in C++
*/
and:
// An in-line comment in C++
C ++ enforces a higher level of type checking than does C. Furthermore, all
functions must be prototyped before use. The next two code fragments show
two ways of doing this.
Firstly, the function can be defined before it is used (in this way the definition
itself forms the prototype):
/* Cube function */
int cube(int x)
{
return x*x*x;
}
/* Main function */
int main()
{
int y;
y = cube(8);
}
Search WWH ::




Custom Search