Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of data Storage in C language

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "example analysis of data storage in C language". In daily operation, I believe that many people have doubts about the analysis of data storage examples in C language. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "data storage example analysis in C language". Next, please follow the editor to study!

I. Type classification

Basic classification of basic c language data types

1. Plastic family char (ascall code value is stored in memory, stored as integer) unsigned char// unsigned is an unsigned keyword signe char//short unsigned short (int) / / (int) means that int can omit signed short (int) int unsigned int signed intlong unsigned long (int) signed long (int) 2, floating point family

Float

Double

3. Pointer type int* ptr;char* pa;float* pf;void* pv;4, null type void indicates null type (no type)

Usually applied to function return types, return parameters, pointer types

Second, the meaning of the type

1. Amount of memory occupied

two。 The size of the operation as data (that is, the point of view of the type of data)

Third, data is stored in types (take shaping and floating-point types as examples). About the basic concept of storage

The signed number of a computer can be expressed in three ways: original code, inverse code, and complement code.

There are two parts of symbol bit and numerical bit in all the three representation methods.'0' is positive,'1' is negative, and the numerical bit representation is different (for unsigned numbers: original, inverse, complement is the same)

Source code: directly translate the numbers into positive and negative, and translate them into binary method.

Inverse code: keep the symbol bits of the original code unchanged, and reverse other bits by bit

Complement: inverse + 1

For positive numbers, the original, inverse, and complement are the same:

Int axiom 20ramp / 00000000 00000000 00000000 00010100 original code / 000000000000000000000000000000010100 inverse code / 000000000000000000000000000000000000010100 complement

For negative numbers

Int await Mustang 1b / 10000000 00000000 00000000 00001010 original code / 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

For plastic data, the complement is stored in memory.

two。 Storage mode

1. Big-end mode (large-end byte order mode): the higher effective bytes are stored at the lower memory address, and the lower significant bytes are stored at the higher memory address.

two。 Small end mode (small end byte order mode): the lower effective bytes are stored at the lower memory address, and the higher significant bytes are stored at the higher memory address.

View of the address

Low-- >-high

About the design to judge the byte order of the current machine

Int check_sys (void) {int astat1; char* p = (char*) & a Bandard / visit the first byte order to see whether it is 01.0 or 0.01 return * p;} int main () {int ret=check_sys (); if (ret==1) printf ("small end"); else printf ("big end");}

Here char* is forced to use the view that he only accesses one byte to observe.

The meaning of pointer type

1. The pointer type determines how many bytes the pointer type dereferencing operator can access.

two。 Pointer + type determines how many bytes pointer + 1 skips.

four。 Application

Plastic improvement of basic concepts that should be mastered before application

1.char axiom Mustang /-1 is stored in memory as a complement as an integer number / / 10000000 00000000 00000000 0000001-original code / / 11111111111111111111111111110-inverse / / 11111111111111111111111111111-complement / / when an is char, only 8 bytes will be stored / truncation will occur / that is, a will be truncated / that is, a will be stored as 1111111signed char / / sigend is the default keyword declaration and declaration defaults to signed / / similarly, b 1111111unsigned char centering color 1pm / c 1111111 treats the high bit as a numeric bit ("% d% d% d", agraine bpenc); / /-1-1 255pm / when printing as% d, plastic lifting should occur / / negative number is signed plastic lifting high position complement 1 / / unsigned lifting high bit complement 0, the original high bit is regarded as a numeric bit / / the complement of the calculation process is converted into the original code, and the result is the result 2.char axim 128pint printf ("% u\ n", a).

Char axioms: 10000000 00000000 00000000 10000000Universe 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000-discussion of char range

Signed (the following are complements)

Signed char range-128127

Examples

Char a [1000]; int I for

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report