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

How to use C _ Candle + basic sizeof

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

The main content of this article is to explain "how to use C _ + basic sizeof". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to use Candlestick + basic sizeof"!

Sizeof () is an operator that determines the type of data or the length of an expression in C _ blank +.

1. Sizeof defines sizeof as an operator (operator) in Cplink +, which returns the number of bytes of memory occupied by an object or type.

The sizeof keyword gives the amount of storage, in bytes, associated with a variable ora type (including aggregate types). This keyword returns a value of type size_t.

-- from MSDN

The return value type is size_t and is defined as: typedef unsigned int size_t in the header file stddef.h

From the definition of sizeof, you can see that sizeof is not a function, because a function call must have a pair of parentheses.

# include int main (void) {int num = 97; printf ("value of sizeof (num = 0):% d\ n", sizeof (num = 0)); printf ("value of num:% d\ n", num); return 0;}

The running result is 4pjm 97; it is not 4pas 0

Note: sizeof is not a unary operator in the standard sense, chain expressions are not supported, and statements within the scope of sizeof will not be compiled into machine code, such as + + in sizeof (num++). Sizeof is not a function either. Sizeof is more like a special macro that is evaluated at compile time.

2. Sizeof usage sizeof has two grammatical forms, as follows:

Sizeof (type_name); / / sizeof (type); sizeof (object); / / or sizeof object all belong to sizeof objects

So:

Int i; sizeof (I); / / reasonable sizeof I; / / reasonable sizeof (int); / / reasonable sizeof int; / / unreasonable

When using sizeof on a type, sizeof type_name is illegal and must be written as sizeof (type_name)

Whether it is a value for an object or a type, the form sizeof () is correct

1) sizeof of basic data types

The basic data types here refer to simple built-in data types such as short, int, long, float, and double.

Because their memory size is related to the system, the values may be different in different systems.

# include using namespace std; int main () {cout

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