Similarities and Differences between Ruby and C language
Similarities between Ruby and C
There are many similarities between C and Ruby, and some of them are:
Like C, in Ruby also…
Differences between Ruby and C
| Ruby | C |
|---|---|
| In Ruby, there is no need to compile the code, it can be run directly. | In C, compilation of code is necessary because it cannot be run directly. |
| It’s require ‘foo’ instead of #include or #include “foo”. | Nothing like that is required in C. |
| There are no variable declarations in Ruby. | Variable declaration is necessary in C. |
| In Ruby, there’s no macros or pre-processor, no casts, no pointers, no typedefs, sizeof, nor enums available. | Whereas, they are present in C. |
| Arguments to methods (i.e. functions) are passed by value, where the values are always object references. | In C functions are passed by value as well as passed by reference. |
| Parentheses for method (i.e. function) calls are often optional. | This is not optional in C. |
| There is no char—they are just 1-letter strings. | Char is used in C for one character. |
| Array literals go in brackets instead of braces in Ruby. | Array literals go in braces in C. |
| You cannot drop down to assembly. | In C you cannot drop down to assembly. |
| In Ruby, objects are strongly typed. | In C, objects are not strongly typed. |
| You go without parentheses for if and while condition expressions. | Parentheses are needed in C with if and while expressions. |
| Strings don’t end with a null byte in Ruby. | While strings ends with a null byte in C. |
| If you add two arrays, you get back a new and bigger array (of course, allocated on the heap) instead of doing pointer arithmetic. | There is a need of pointer arithmetic in C. |
| In Ruby, arrays just automatically get bigger when you stuff more elements into them. | In C, automatically array cannot gets bigger. |
| All variables live on the heap. Further, you don’t need to free them yourself—the garbage collector takes care of that. | In C, we need to free them ourself because garbage collector is not present in C. |
| You don’t usually use braces—just end multi-line constructs (like whileloops) with an end keyword. | Braces are required because ignoring braces will cause syntax error. |
| All the functions and classes are defined in the main source code files as there are no header files present in ruby. | Header files are present in C. |
| There’s no semicolons ending lines. | There is ending lines. |
| There’s no #define in ruby. Just use constants. | #define is there in C. |
| The do keyword is for so-called “blocks”. There’s no “do statement” like in C. | Do statement is used in C with while to make a loop like do-while. |
Recommended Posts:
- Similarities and Differences between Ruby and C++
- Ruby Programming Language (Introduction)
- Interesting facts about Ruby Programming Language
- Differences between TCP and UDP
- Differences between JDK, JRE and JVM
- Differences between Data paths
- Differences between Bootstrap and JQuery UI
- Differences between IPv4 and IPv6
- What are the differences between HTTP, FTP, and SMTP?
- Differences between POP3 and IMAP
- Differences between Testing and Debugging
- Differences between 8086 and 8088 microprocessors
- Differences between Flatten() and Ravel() | Numpy
- Differences between Interface and Integration Testing
- Differences between Interface and Class in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


