小编sim*_*onc的帖子

C++循环性能:变量初始化

变量将被设置为数千次的值.检查变量是否已设置为这样的值是否更好?

    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 ctimeclock()功能),他们在结果中给出了相同的62ms.那么它是否意味着没有实际差异?

c++ variables performance initialization

-1
推荐指数
1
解决办法
256
查看次数

恼人的C++ gcc警告信息

我编写了以下程序来匹配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)

c++

-3
推荐指数
1
解决办法
285
查看次数

对于'c'中的循环

#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)

然后错误被删除.你能解释一下这是如何工作的吗?

c

-4
推荐指数
1
解决办法
135
查看次数

"printf"无法在线程上正常工作?

代码如下:

#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时它什么都没打印出来!当我运行它更多时间:

耶!打印出来:开始...取...

为什么?

c

-4
推荐指数
1
解决办法
155
查看次数

(极端Noob在这里)为什么这个C代码不起作用?

为什么这不起作用,我对编程很新,但我似乎无法弄清楚为什么这不能正常工作.

#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)

c

-5
推荐指数
2
解决办法
236
查看次数

跟随C代码编译错误的原因

?#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)

c compilation syntax-error

-5
推荐指数
1
解决办法
852
查看次数

有人可以解释C指针

有人可以解释为什么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)

c pointers

-6
推荐指数
1
解决办法
152
查看次数

静态类和非静态类有什么区别?

有人可以解释一下这两个班级之间的区别吗?

我总是使用第一个,但我经常使用第二个.

public static class Test
{
    public static void Method()
    {

    }
}


public class Test
{
    public static void Method()
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

c#

-8
推荐指数
1
解决办法
238
查看次数

在C++中使用printf输出浮点数

我正在尝试输出一个浮点数

printf(theFloat);
Run Code Online (Sandbox Code Playgroud)

但是,这给了我以下错误。

““float”类型的参数与“const char *”类型的参数不兼容”

我不确定为什么这不起作用,我查看了一下,发现人们使用printf格式化浮点数...是否还有另一种用于浮点数等的打印方法?

c++ floating-point printf

-8
推荐指数
1
解决办法
3173
查看次数