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

What does * in C language mean?

May 07, 2024 am 08:18 AM
c language

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:

    int *ptr;  // 声明一个指向 int 类型的指针
    Copy after login
  • is used to get the value of the variable pointed to by the pointer. For example:

    *ptr = 10;  // 将 ptr 指向的变量赋值为 10
    Copy after login
  • is used to get the address of the variable pointed to by the pointer. For example:

    int num = 20;
    int *ptr = #  // 将 ptr 指向 num 变量的地址
    Copy after login

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:

    *ptr++  // 等同于 ++(*ptr)
    Copy after login

3. The dereference operator

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

    struct student *stu;
    struct student& stu_ref = *stu;  // 获取 stu 指向的 student 类型的引用
    Copy after login

4. The multiplication operator

  • is used to perform multiplication operations. For example:

    int x = 5;
    int y = 2;
    int z = x * y;  // z 的值为 10
    Copy after login

5. Dereference pointer

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

    int *ptr;  // 声明一个指向 int 类型的指针
    int num = 20;
    ptr = # // ptr 指向 num 变量的地址
    *ptr;  // 解引用 ptr,返回 num 变量的地址
    Copy after login

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 of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Usage of typedef struct in c language Usage of typedef struct in c language May 09, 2024 am 10:15 AM

Usage of typedef struct in c language

The difference between strcpy and strcat in c language The difference between strcpy and strcat in c language May 08, 2024 pm 01:03 PM

The difference between strcpy and strcat in c language

What does real mean in c language What does real mean in c language May 09, 2024 pm 12:06 PM

What does real mean in c language

How to implement the power function in C language How to implement the power function in C language May 09, 2024 pm 11:33 PM

How to implement the power function in C language

What to do if there is an error in scanf in C language What to do if there is an error in scanf in C language May 09, 2024 am 11:39 AM

What to do if there is an error in scanf in C language

How to use restrict in c language How to use restrict in c language May 08, 2024 pm 01:30 PM

How to use restrict in c language

_complex usage in c language _complex usage in c language May 08, 2024 pm 01:27 PM

_complex usage in c language

_What does bool mean in c language? _What does bool mean in c language? May 08, 2024 pm 01:33 PM

_What does bool mean in c language?

See all articles