What is the difference between ++i and i++?

在C中,使用++i和i++什么区别,哪些应该用在for循环的增量块中? ++i will increment the value of i , and then return the incremented value. i = 1; j = ++i; (i is 2, j is 2) i++ will increment the value of i , but return the original value that i held before being incremented. i = 1; j = i++; (i is 2, j is 1) For a for loop, either works. ++i seems more common, perhaps because that is what

++ i和i ++有什么区别?

在C中,使用++i和i++什么区别,哪些应该用在for循环的增量块中? ++i将递增的值i ,然后返回增加后的值。 i = 1; j = ++i; (i is 2, j is 2) i++将增加的价值i ,而是返回原来的价值i递增之前举行。 i = 1; j = i++; (i is 2, j is 1) 对于for循环来说,可以工作。 ++i似乎更常见,也许是因为这是K&R中使用的。 在任何情况下,请遵循指导原则“prefer ++i over i++ ”,并且不会出错。 关于++i和i++的效率,有几条

What does the constant 0.0039215689 represent?

I keep seeing this constant pop up in various graphics header files 0.0039215689 It seems to have something to do with color maybe? Here is the first hit on Google: void RDP_G_SETFOGCOLOR(void) { Gfx.FogColor.R = _SHIFTR(w1, 24, 8) * 0.0039215689f; Gfx.FogColor.G = _SHIFTR(w1, 16, 8) * 0.0039215689f; Gfx.FogColor.B = _SHIFTR(w1, 8, 8) * 0.0039215689f; Gfx.FogColor.A = _SHIFTR

常数0.0039215689代表什么?

我一直看到这个常量在各种图形头文件中弹出 0.0039215689 这似乎与颜色有关? 这是Google的第一个热门游戏: void RDP_G_SETFOGCOLOR(void) { Gfx.FogColor.R = _SHIFTR(w1, 24, 8) * 0.0039215689f; Gfx.FogColor.G = _SHIFTR(w1, 16, 8) * 0.0039215689f; Gfx.FogColor.B = _SHIFTR(w1, 8, 8) * 0.0039215689f; Gfx.FogColor.A = _SHIFTR(w1, 0, 8) * 0.0039215689f; } void RDP_G_SETBLENDCOLOR(void) {

t variable portably using the printf family?

I have a variable of type size_t , and I want to print it using printf() . What format specifier do I use to print it portably? In 32-bit machine, %u seems right. I compiled with g++ -g -W -Wall -Werror -ansi -pedantic, and there was no warning. But when I compile that code in 64-bit machine, it produces warning. size_t x = <something>; printf( "size = %un", x ); warning: format '%u'

可变的可移植使用printf家族?

我有一个size_t类型的变量,我想用printf()来打印它。 我使用哪种格式说明符来轻松打印? 在32位机器中, %u似乎是正确的。 我编译了g ++ -g -W -Wall -Werror -ansi -pedantic,并没有任何警告。 但是当我在64位机器中编译该代码时,它会产生警告。 size_t x = <something>; printf( "size = %un", x ); warning: format '%u' expects type 'unsigned int', but argument 2 has type 'long unsigned int' 如

while statement error fool proof

The error occurs in the while loop at int getInt(void) I want to loop and ask the user to input a number, so like if they input 10 it would pass, but if they were to input 10abc it should loop and ask again and keep asking until a valid input is made. It should be foolproof so it will only pass with a number on its own and thats it. For some reason the printf statement inside the while loop inf

同时声明错误的傻瓜证明

这个错误发生在int getInt(void)的while循环中,我想循环并要求用户输入一个数字,所以就像他们输入10那样它会通过,但是如果他们要输入10abc,它应该循环并再次询问并且不断询问,直至获得有效的输入。 它应该是万无一失的,所以它只会通过一个数字来处理它,而那就是它。 出于某种原因,while循环内的printf语句无限循环,我无法输入新值。 {#include <stdio.h> void welcome(void); int getInt(void); double getD

Writing C main function

This question already has an answer here: What should main() return in C and C++? 19 answers The return value of main() is used to indicate success or failure to its parent process. More generally, it can be used to communicate back specific statuses as well, though C doesn't define those. If main() returns 0 or EXIT_SUCCESS , then the program was successful. EXIT_FAILURE or non-zero

写C主要功能

这个问题在这里已经有了答案: main()应该在C和C ++中返回什么? 19个答案 main()的返回值用于指示其父进程的成功或失败。 更一般地说,它也可以用来反馈特定的状态,尽管C没有定义这些状态。 如果main()返回0或EXIT_SUCCESS ,那么程序成功。 EXIT_FAILURE或非零,则失败。 参数列表中的void只是表示它不带任何参数。 这是因为C的一个(错误)特征,它允许你声明一个函数而不需要完全指定它所需要的参数。 一个

Why would you precede the main() function in C with a data type?

This question already has an answer here: What should main() return in C and C++? 19 answers The following has been valid in C89 main() { return 0; } But in modern C (C99), this isn't allowed anymore because you need to explicitly tell the type of variables and return type of functions, so it becomes int main() { return 0; } Also, it's legal to omit the return 0 in modern C,

你为什么要在C语言的main()函数中加上数据类型?

这个问题在这里已经有了答案: main()应该在C和C ++中返回什么? 19个答案 以下在C89中有效 main() { return 0; } 但在现代C(C99)中,这是不允许的,因为你需要明确地告诉变量的类型和函数的返回类型,所以它变成了 int main() { return 0; } 此外,在现代C中省略return 0是合法的,因此写法是合法的 int main() { } 行为就好像它返回0。 人们把void的括号内,因为它确保函数调用正确的类型检查。 C中的

Cannot modify C string

Consider the following code. int main(void) { char * test = "abcdefghijklmnopqrstuvwxyz"; test[5] = 'x'; printf("%sn", test); return EXIT_SUCCESS; } In my opinion, this should print abcdexghij. However, it just terminates without printing anything. int main(void) { char * test = "abcdefghijklmnopqrstuvwxyz"; printf("%sn", test); return EXIT_SUCCESS; } This howev

无法修改C字符串

考虑下面的代码。 int main(void) { char * test = "abcdefghijklmnopqrstuvwxyz"; test[5] = 'x'; printf("%sn", test); return EXIT_SUCCESS; } 在我看来,这应该打印abcdexghij。 然而,它只是终止而不打印任何东西。 int main(void) { char * test = "abcdefghijklmnopqrstuvwxyz"; printf("%sn", test); return EXIT_SUCCESS; } 然而,这工作得很好,所以我误解了操纵C字符串或什么的概

Forcing a custom HTTP 401 unauthorized page in ASP.NET

I've written a web application for internal use at work (not for the wider internet) that makes use of Windows authentication - ASP.NET interrogating Windows for the current set of credentials. An authentication method called from the Page_PreInit of protected pages throws a 401 error if the username is not found in an AD group I've set up. I implemented Earlz' CustomErrorsFixer fr

在ASP.NET中强制定制HTTP 401未经授权的页面

我已经编写了一个Web应用程序供内部使用(不适用于更广泛的互联网)使用Windows身份验证 - ASP.NET正在询问Windows当前的凭据集。 如果在我设置的AD组中找不到用户名,则从受保护页面的Page_PreInit调用的身份验证方法将引发401错误。 我从抛出一个HttpException实现了Earlz的CustomErrorsFixer总是发回HTTP 500错误? 因为我也只得到500回来。 现在我的自定义错误页面正在工作,这很好。 在Visual Studio开发服务器本地

Very lengthy stored procedure status

I have a stored procedure which takes about 5-8 mins to execute. The user just sees a message "Please wait while report is being generated" It is very likely that people may think that it has stopped working ... or something went wrong.. etc.. Is there any way a stored procedure can keep returning status while executing..? for example : {logical block 1} logical block 1 completed!

非常冗长的存储过程状态

我有一个存储过程需要大约5-8分钟执行。 用户只会看到一条消息“正在生成报告请等待”很可能人们会认为它已停止工作......或出现问题等等。 存储过程有没有办法在执行时保持返回状态? 例如 : {logical block 1} logical block 1 completed! {logical block 2} logical block 2 completed! {logical block 3} logical block 3 completed! 如果是的话,请告诉我如何在c#中捕获这些状态。 多谢你们。 有趣! 你看过非

Right To Left Bracket display wrong

When the Label text value ends with end bracket. The result in Right to Left is wrong like example. Text: ABC (123) Result: (ABC (123 Expected Result: ABC (123) Is there any solution to fix it? You have to use the Unicode Right-to-left mark , ( U+200F ) in your text. Conversely, use the Left-to-right mark (`U+200E) if you know you need LTR rendering. Check your input encoding.you should

从右到左括号显示错误

当标签文本值以尾括号结尾时。 例如,从右到左的结果是错误的。 Text: ABC (123) Result: (ABC (123 Expected Result: ABC (123) 有没有解决方案来解决它? 您必须在文本中使用Unicode Right-to-left mark ( U+200F )。 相反,如果你知道你需要LTR渲染,使用Left-to-right mark (`U + 200E)。 检查你的输入编码。你应该使用UTF系列或unicode来获得你的目标。 还请在Visual Studio中检查您的文件编码。