Home  >  Article  >  Backend Development  >  A brief discussion on the similarities and differences between Ruby and C language

A brief discussion on the similarities and differences between Ruby and C language

青灯夜游
青灯夜游Original
2019-01-22 17:45:176779browse

What are the similarities and differences between Ruby and C language? This article will give you a brief introduction to the similarities and differences between Ruby and C language. I hope it will be helpful to you.

A brief discussion on the similarities and differences between Ruby and C language

The similarities between Ruby and C language

1. Both languages ​​have the same operations operators, such as compound assignment and bitwise operators.

2. Both of them have __FILE__ and __LINE__.

3. There is no special const keyword, but we can still have constants.

4. In C and Ruby, strings are represented by double quotes, that is, "".

5. They all contain variable strings.

6. Using the ri command, most documents can be read in the terminal, just like manual pages.

7. Both command line debuggers can use the same type of command line debugger.

The difference between Ruby and C language

1. Compile and run

In Ruby, there is no need to compile the code, it can be run directly. In C, compiling the code is necessary because it cannot be run directly.

2. Variable declaration

There is no variable declaration in Ruby; however, variable declaration is required in C.

3. Macros or preprocessors, casts, pointers, typedef, sizeof, enumerations

In Ruby, there are no macros or preprocessors, no coercion There are no enumerations available for conversion, pointers, typedef, sizeof, but they are all available in C.

4. Type of object

In Ruby, objects are strongly typed; in C, objects are not strongly typed.

5. Header file

There is no header file in ruby, so all functions and classes are defined in the main source code file; header files exist in C.

6. End of string

Strings in Ruby do not end with null bytes. Strings in C are null byte terminated.

7. Function value passing

In Ruby, function parameters are passed by value, where the value is always an object reference. In C functions, values ​​are passed by value and also by reference.

8. do keyword

In Ruby, the do keyword is used for so-called "blocks". Use Do statements in C while making loops like do-while.

The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of A brief discussion on the similarities and differences between Ruby and C language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn