变量将被设置为数千次的值.检查变量是否已设置为这样的值是否更好?
int a = 0;
while (true) {
if (a != 3) a = 3;
}
Run Code Online (Sandbox Code Playgroud)
或者我应该离开它:
int a = 0;
while (true) {
a = 3;
}
Run Code Online (Sandbox Code Playgroud)
PS我在Visual Studio 2010中使用15000次迭代进行了一些实际测试(使用#include ctime和clock()功能),他们在结果中给出了相同的62ms.那么它是否意味着没有实际差异?
我编写了以下程序来匹配C++中的正则表达式
#include <regex.h>
#include <iostream>
using namespace std;
/*
* Match string against the extended regular expression in
* pattern, treating errors as no match.
*
* return true for match, false for no match
*/
bool match(const char *string, char *pattern)
{
int status; regex_t re;
if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0)
return false;
/* report error */
status = regexec(&re, string, (size_t) 0, NULL, 0);
regfree(&re);
if (status != 0) {
return false; /* report error */
} …Run Code Online (Sandbox Code Playgroud) #include<stdio.>
#include<conio.h>
void main()
{
for(;;);
getch();
}
Run Code Online (Sandbox Code Playgroud)
编译时为getch()提供错误无法访问的代码..当编译时没有分号if
void main()
{
for(;;)
getch();
}
Run Code Online (Sandbox Code Playgroud)
然后错误被删除.你能解释一下这是如何工作的吗?
代码如下:
#include <pthread.h>
#include <stdio.h>
void* fetch();
int main(int argc, char *argv[])
{
pthread_t tid;
pthread_create(&tid, NULL, &fetch, NULL);
}
void* fetch()
{
printf("start...\n");
int i;
for (i = 0; i < 100; i++)
{
printf("fetch...\n");
}
pthread_exit(0);
}
Run Code Online (Sandbox Code Playgroud)
为什么这段代码不能正常运行我运行它多次.救命!当我做$ gcc thread_test.c $./ a.out时它什么都没打印出来!当我运行它更多时间:
耶!打印出来:开始...取...
为什么?
为什么这不起作用,我对编程很新,但我似乎无法弄清楚为什么这不能正常工作.
#include <stdio.h>
#include <math.h>
int main(){
int num1;
printf("Enter 1, 2, 3.");
scanf("%d", &num1);
if(num1 = 1)
printf("You entered one");
else if(num1 = 2)
printf("You entered two");
else if(num1 = 3)
printf("You entered three");
else
printf("Invalid");
}
Run Code Online (Sandbox Code Playgroud) ?#include? <stdio.h>
void main(void)
{
char cValue='a';
int iValue=1234567;
long 1Value=7890123;
float fValue=3.141592;
double dValue=3.141592;
char*string="korea";
char buffer[100];
sprintf(buffer,"char type is %c", cValue);
puts(buffer);
sprintf(buffer,"int type is %d", iValue);
puts(buffer);
sprintf(buffer,"long type is %1d", 1Value);
puts(buffer);
sprintf(buffer,"float type is %f", fValue);
puts(buffer);
sprintf(buffer,"double type is %e", dValue);
puts(buffer);
sprintf(buffer,"char* type is %s", string);
puts(buffer);
}
Run Code Online (Sandbox Code Playgroud)
当我使用此代码编译时,出现语法和其他错误.
这段代码有什么问题?
错误消息:
76\76.c(7) : error C2059: syntax error : 'bad suffix on number'
76\76.c(7) : error C2143: syntax error : missing ';' before 'constant' …Run Code Online (Sandbox Code Playgroud) 有人可以解释为什么v [2]最终得到的值为-3,而不是为空,或者25为什么?
#include <stdio.h>
int main ()
{
int v[5];
int *z = &v[0];
*z=12;
z++;
*z=16;
z++;
*z=-3;
z++;
*z=25;
printf ("%d", v[2]);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 有人可以解释一下这两个班级之间的区别吗?
我总是使用第一个,但我经常使用第二个.
public static class Test
{
public static void Method()
{
}
}
public class Test
{
public static void Method()
{
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试输出一个浮点数
printf(theFloat);
Run Code Online (Sandbox Code Playgroud)
但是,这给了我以下错误。
““float”类型的参数与“const char *”类型的参数不兼容”
我不确定为什么这不起作用,我查看了一下,发现人们使用printf格式化浮点数...是否还有另一种用于浮点数等的打印方法?
c ×5
c++ ×3
c# ×1
compilation ×1
performance ×1
pointers ×1
printf ×1
syntax-error ×1
variables ×1