Home >Backend Development >C#.Net Tutorial >What does * in C language mean?

What does * in C language mean?

下次还敢
下次还敢Original
2024-05-07 08:18:16527browse

The * symbol in C language has five meanings: 1. Pointer operator, declares a pointer; 2. Gets the value of the variable pointed by the pointer; 3. Gets the address of the variable pointed by the pointer; 4. Indirect addressing operator , access the variable pointed by the pointer; 5. Dereference operator, obtain the reference of the type pointed by the pointer.

What does * in C language mean?

The * symbol in C language

The asterisk (*) in C language is an operator , has the following meanings:

1. Pointer operator

  • is used to declare a pointer. For example:

    <code class="c">int *ptr;  // 声明一个指向 int 类型的指针</code>
  • is used to get the value of the variable pointed to by the pointer. For example:

    <code class="c">*ptr = 10;  // 将 ptr 指向的变量赋值为 10</code>
  • is used to get the address of the variable pointed to by the pointer. For example:

    <code class="c">int num = 20;
    int *ptr = &num;  // 将 ptr 指向 num 变量的地址</code>

2. The indirect addressing operator

  • is used to access variables pointed to by pointers. Equivalent to using the pointer operator to obtain the value of the variable pointed to by the pointer. For example:

    <code class="c">*ptr++  // 等同于 ++(*ptr)</code>

3. The dereference operator

  • is used to obtain a reference to the type pointed to by the pointer. For example:

    <code class="c">struct student *stu;
    struct student& stu_ref = *stu;  // 获取 stu 指向的 student 类型的引用</code>

4. The multiplication operator

  • is used to perform multiplication operations. For example:

    <code class="c">int x = 5;
    int y = 2;
    int z = x * y;  // z 的值为 10</code>

5. Dereference pointer

  • is used to dereference a pointer and return the variable it points to. the address of. For example:

    <code class="c">int *ptr;  // 声明一个指向 int 类型的指针
    int num = 20;
    ptr = &num; // ptr 指向 num 变量的地址
    *ptr;  // 解引用 ptr,返回 num 变量的地址</code>

The above is the detailed content of What does * in C language mean?. 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