当前位置:网站首页>[C language] analysis of variable essence

[C language] analysis of variable essence

2022-06-12 03:48:00 Embedded workplace

Catalog

1、 Variable concept

2、 The nature of variables

3、 Experimental verification


1、 Variable concept

Objects that can read and write memory variables are called variables ;

Objects that cannot be modified once initialized are called constants ;

Definition of variables

Type the name   identifier 、 identifier ;

for example :

int i,j,m,n;
char num;
double k;
float fan;

2、 The nature of variables

(1) The program uses variables to apply for and name memory space int a = 0

(2) Access memory space by variable name

(3) There are ways to modify variables ???

  • direct , Change the value of the variable ;
  • indirect , Get the address number of the variable , You can modify variables ;

Define variables by data types ;

3、 Experimental verification

  • Read and write variables ;
  • Read and write data to memory through variables ;
  • Not reading and writing data to variables , Instead, write data to the memory space represented by the variable ;

Three elements of variable ( name 、 size 、 Scope ).

#include <stdio.h>

int main(){
    // Operating memory through variables 
    int n = 10;
    printf("&n:%d\n",&n);

    // Modify variables by memory address , among &n = 6356508
    *((int*)(6356508)) = 20;
    printf("n = %d\n",n);

    return 0;
}

Result display :

原网站

版权声明
本文为[Embedded workplace]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120343482817.html