Home >Backend Development >C#.Net Tutorial >What does %r mean in c language

What does %r mean in c language

下次还敢
下次还敢Original
2024-05-02 18:21:15680browse

In C language, the %r conversion specifier is used for: Formatted output: Print the address of a pointer variable, and the result is usually displayed in hexadecimal format. Formatted input: Read and store the input address into a pointer variable.

What does %r mean in c language

%r in C language is the conversion specifier for formatted output

%r is in C language Formatted output and input conversion specifiers commonly used in the printf() and scanf() functions. It is used to print or read the value of a pointer.

Formatted output (printf() function):

  • Usage: printf("%r", &variable);
  • Effect: Print the address of the variable.

Formatted input (scanf() function):

  • Usage: scanf("%r", &variable );
  • Effect:Read an address from the input and store it in the variable.

Note: The

  • %r conversion specifier only applies to pointer variables.
  • When printing pointer variables, the output results will vary depending on the compiler and platform. Addresses are usually printed in hexadecimal format.
  • When reading a pointer variable, the input must be a valid memory address. Otherwise, the read operation will fail.

Example:

<code class="c">int main() {
    int *ptr = malloc(sizeof(int));
    *ptr = 10;

    printf("Pointer value: %r\n", ptr);  // 输出指针地址
    scanf("%r", &ptr);  // 从输入中读取指针地址

    printf("Dereferenced pointer value: %d\n", *ptr);  // 输出通过指针访问的值

    return 0;
}</code>

The above is the detailed content of What does %r mean in 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