You might have came across these statements, C is more optimised or performance of C is better than higher languages, so I’ll be discussing the reasons for this hypothesis.
First let’s list out functionalities which are provided by languages like Java and not C :
- Array index bound checking
- Uninitialized variable values checking
- Check for memory leaks
- Check for null pointer dereference
- Automatic garbage collection
- Run-time type checking
- Exception handling
and there are more such features which are not present in C.
Extra features comes at cost and the cost includes decreased speed and increased size.
Let’s take an example for dynamic allocation in C and Java
MyClass obj = new MyClass();
Did you considered size of obj, the answer is No. The reason being it is automatically handled by language itself in background and you don’t have to write specific code for it.
But in case of C
struct MyStruct *obj = malloc(sizeof(struct MyStruct));
As you can see in above code the tasks of assigning reference to pointer, allocation of size is done explictly by programmer and at last free up allocated memory.
The array bound check is supported by Thumb Execution Environment (ThumbEE), its other features includes automatic null pointer checks on every load and store instruction, an special instruction that call a handler.
Another reason is closeness of C to the Assembly language, in most of the cases its instructions directly map to assembly language, C is only one or level two levels of abstraction away from assembly language while Java is at minimum 3 levels abstraction away from assembler.
This article is contributed by Mandeep Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Why are elementwise additions much faster in separate loops than in a combined loop?
- Benefits of C language over other programming languages
- getchar_unlocked() - faster input in C/C++ for Competitive Programming
- Which will be faster while(1) or while(2)?
- Role of SemiColon in various Programming Languages
- Top 10 Programming Languages for Blockchain Development
- Format specifiers in different Programming Languages
- Why C treats array parameters as pointers?
- Why is the size of an empty class not zero in C++?
- Why copy constructor argument should be const in C++?
- Why "&" is not used for strings in scanf() function?
- Why is a[i] == i[a] in C/C++ arrays?
- Why variable name does not start with numbers in C ?
- Why only subtraction of addresses allowed and not division/addition/multiplication
- Why strict aliasing is required in C ?
- Why does sizeof(x++) not increment x in C?
- Why strcpy and strncpy are not safe to use?
- Why array index starts from zero ?
- Why learning C Programming is a must?
- Why to use fgets() over scanf() in C?