I'm currently writing up a report and had a couple of question I want to
clarify:
Is it 'c' or 'C'?
The name of the language should be spelled in uppercase.
In C++ an instance of a class is an 'Object'. Is an instance of a struct
also an 'Object' in c/C?
If you use a fly to fish, be sure to zip your fly. If you buy it
on a credit card, do not expect to get a credit.
I mention
all this because the literal answer to your question is "yes", but
the word "object" means something different in C++ than in C, just
as your fly (on your pants) is not your fly (on the end of your
fishing line).
Is there a 'const' keyword in Standard c/C?
Yes.
Can you use it to declare array sizes as I can in C++?
No and yes. The const keyword in C means something different than
the const keyword in C++. In the 1989 ANSI C standard -- which is
also the 1990 ISO C standard, and is often referred to as either
C89 or C90 -- an array size must be an integer constant expression
(or omitted entirely, in cases like "extern int a[];"). Variables
defined with the "const" keyword are still variables, despite being
read-only (at least in principle), so they may not be used to give
the size of an array.
In the 1999 C standard (both ANSI and ISO), however, there is a new
kind of array, the "variable length array" or VLA, whose size is not
required to be a constant. Since "const" variables are variables,
not constants, they can be used where VLAs are allowed (inside
functions), but not where VLAs are forbidden. Thus:
const int k = 20;
int arr[k]; /* illegal in both C89 and C99 */
extern int somefunc(void);
void f(void) {
int arr2[k]; /* illegal in C89, legal in C99 */
int arr3[somefunc()]; /* likewise legal only in C99 */
...
}
C and C++ are really very different languages, despite syntactic
similarities. While one can write in a contorted "subset language"
so that one's programs are valid in both C (89 and 99) and C++,
and even have the same semantics in both (note that it is not
difficult to write programs that have different semantics), such
programs are rarely "good style" in either language. For instance,
C++ programmers should eschew malloc() in favor of either "new" or
container-classes, and C programmers should avoid casting malloc()
calls (generally required in C++).