gpt4 book ai didi

c - 打印 : Is this safe?

转载 作者:太空狗 更新时间:2023-10-29 15:19:35 26 4
gpt4 key购买 nike

我只是想知道这个表达式是否安全:

int main (void)
{
char my_tab[256];

memset(my_tab,0x61,sizeof(my_tab));

printf("Is it safe ? : %.256s",my_tab); /* is it safe ? */
}

最佳答案

是的,您将打印出 256 个字符,仅此而已。

来自 C11 标准 7.21.6。 p4:

An optional precision that gives the minimum number of digits to appear for the d, i, o, u, x, and X conversions, the number of digits to appear after the decimal-point character for a, A, e, E, f, and F conversions, the maximum number of significant digits for the g and G conversions, or the maximum number of bytes to be written for s conversions. The precision takes the form of a period (.) followed either by an asterisk * (described later) or by an optional decimal integer; if only the period is specified, the precision is taken as zero. If a precision appears with any other conversion specifier, the behavior is undefined.

7.21.6.1。 p8:

s : If no l length modifier is present, the argument shall be a pointer to the initial element of an array of character type. Characters from the array are written up to (but not including) the terminating null character. If the precision is specified, no more than that many bytes are written. If the precision is not specified or is greater than the size of the array, the array shall contain a null character.

关于c - 打印 : Is this safe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26281990/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com