📜  PHP和 C 的异同

📅  最后修改于: 2021-09-13 02:55:28             🧑  作者: Mango

PHP是一种专门为 Web 开发设计的服务器端脚本语言。它可以很容易地嵌入到 HTML 文件中,也可以将 HTML 代码编写在PHP文件中。 PHP与 HTML 等客户端语言的区别在于, PHP代码在服务器上执行,而 HTML 代码直接在浏览器上呈现。

C 是一种过程编程语言。它最初由丹尼斯·里奇 (Dennis Ritchie) 开发,作为一种用于编写操作系统的系统编程语言。 C 语言的主要特点包括对内存的低级访问、一组简单的关键字和干净的风格,这些特点使 C 语言适用于操作系统或编译器开发等系统编程。

PHP和 C 之间的相似之处

Parameters Similarities
Syntax
  1. Code is not sensitive to blanks.
  2. Semicolons are used for terminating a sentence.
  3. Functions are called in a similar fashion.
  4. Curly brackets are used for enclosing code in a block.
  5. C and C++ comment style is supported by PHP.
Operators All type of operators in C behave in similar way in PHP, such as basic arithmetic, boolean, assignment and comparison operators.
Control Structure
  1. The primary control structures such as, if-else, while, for, do-while,etc function in similar way in both the languages.
  2. Break and continue are available in both PHP and C.
  3. Switch is also same, except that in PHP strings are also accepted as case identifiers.
Function prototype User defines functions are named in same way in both the languages.

PHP和 C 之间的差异

Parameters PHP C
Data types PHP has only two numerical data type:
  • integer(can be compared to long in C)
  • double(can be compared to double in C)

Strings are of random length and there is no character data type available in PHP.

C has:
  • Primary data types(such as int, double, float, char, void, etc.)
  • Derived data types(array, structure, union and pointer)
Type Conversion Data types are not checked during compile-time and data type errors are rare to occur. Values and variables are automatically cast into the suitable data type. In C variables are declared with data types. While some data types have implicit conversion, others need to be type-casted.
Data type error occurs in C commonly and should be taken care.
Array Superficially they look similar to arrays in C.
  • Array need not be allocated or declared in advance.
  • The indexes can be opted by user- string or a number.
  • They are used for hashing are known as associative arrays.
  • Array needs to be allocated or declared in advance.
  • Their data types and memory allocation is done before they are used in the code.
  • The indexes can be only numbers starting from 0.
Structure No structure type needed because of array and objects. Structure type exists in C.
Prototypes There are no prototype in PHP because function is not required to be declared before it’s implementation. There are prototypes in C because function is required to be declared before its implementation.
Permissiveness PHP is a lot more lenient when compared to C. More than errors there are unexpected results for making new mistakes. C will give errors if data type is not declared, array size is not declared, etc.
Comparing it to PHP it is a little stricter.
想要从精选的视频和练习题中学习,请查看C 基础到高级C 基础课程