Topic-Keyword Secrets

    The secret of keywords is divided into the above 8 aspects for analysis. Let’s talk about the video understanding of basic data type analysis:

            1. The basic data type can be understood as the size of fixed memory. The program uses variables to apply for memory space before using the memory space. The data type is the general name of the variable in memory, and the essence of the variable is the alias of the continuous memory space ;

                                                                            

        As shown in the figure above, char, short and int are data types, c, s, i are variable names, char represents a memory space model with a size of 1 byte, and c is an actual mold name made by this model in the memory space That is, the variable name, the program can use this memory space through the variable c.

        The following is the code verification link in the video, but I don't have a Linux system, so I just use vs2015 to verify it:

#include "stdafx.h"

int main()
{
char c1,c2;
short s, m;
int i, j;


c1 = 0; c2 = 0;
s = 0; m = 0;
i = 0; j = 0;


printf("%d, %d\n", unsigned int(sizeof(char)), unsigned int(sizeof(c1)));
printf("%d, %d\n", unsigned int(sizeof(short)), unsigned int(sizeof(s)));
printf("%d, %d\n", unsigned int(sizeof(int)), unsigned int(sizeof(i)));


printf("addressC1 = 0x%08x, addressC1 = 0x%08x\n", &c1, &c2);
printf("addressS = 0x%08x, addressM = 0x%08x\n", &s, &m);
printf("addressI = 0x%08x, addressJ = 0x%08x\n", &i, &j);


return 0;

}

The result is as follows:


    doubt:

        1. The int type variable is 4 bytes, which is correct from the address, but the short type variable is not correct! Seems to be 4 bytes from the address? The char type is also correct;

        2. It is said in the video that the addresses of variables in memory are continuous. From this result, it seems that they are not continuous?

    Doubt for now, think about it later! If there is a mistake, please correct it!


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324515267&siteId=291194637