I saw video on classes and objects on youtube , the code was in java
but instructor said it is same for other languages too.
That was somewhat irresponsible of the instructor. Some other languages have syntax similar to Java's for defining classes -- most notably, C++. On the other hand, some other OO languages have quite different syntaxes, and some don't even use the term "class", much less a keyword with that spelling.
I have learnt some basic in C language. When I opened Code::Blocks and typed "class" it highlighted
"class" is not a C keyword, so it is counterproductive to highlight it as one in C code. If that is what Code::Blocks was doing (for a .c file) then that would constitute a flaw. But if it was highlighting that word as an identifier (a variable name) then it was behaving reasonably.
and then i compiled it without any error.
... but with some warnings that you mention only later:
warning: data definition has no type or storage class
warning: type defaults to ‘int’ in declaration of ‘class’ [-Wimplicit-int]
These are telling you that your code is being interpreted differently than you probably expected.
The two are related. They are telling you that "class" is being treated as an indentifier (of a variable), not as a language keyword. They are furthermore telling you that the type of that identifier is being implicitly assigned as int
, which is a compatibility feature of GCC and some other C compilers. Since C99, such a declaration is not valid in C, and if you use a strict(er)-conformance compilation option, such as -std=c99
, then the compiler will reject it.
I know that C isn't a OOP language so it should not contain classes.
Does not contain classes would be a more appropriate way to phrase it. But that doesn't mean it recognizes the word "class" as something it should specifically reject. Rather, it means that the word "class" is not recognized as anything special.