小编Wed*_*shi的帖子

三个参数功能模板令人困惑的例子

#include <iostream>

// maximum of two values of any type:
template<typename T>
T max (T a, T b)
{
    std::cout << "max<T>() \n";
    return b < a ? a : b;
}

// maximum of three values of any type:
template<typename T>
T max (T a, T b, T c)
{
    return max (max(a,b), c); // uses the template version even for ints
} //because the following declaration comes
// too late:

// maximum of two int values:
int max …
Run Code Online (Sandbox Code Playgroud)

c++ stl

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

malloced指针在返回时更改值

我的代码看起来像这样:

Foo* create(args) {
    Foo *t = malloc (sizeof (Foo)) ;
    // Fill up fields in struct t from args. 
    return t;
} 
Run Code Online (Sandbox Code Playgroud)

电话是

Foo *created = create (args) 
Run Code Online (Sandbox Code Playgroud)

请注意,函数和函数调用是两个独立的模块.分配给该指针的值t上是mallocED是什么是在捕获的稍有不同created.似乎地址的MSB已更改并替换为fffff.LSB部分对于大约6-7个字符是相同的.

我不知道发生了什么.我正在使用GCC 4.6

c

0
推荐指数
1
解决办法
97
查看次数

在C中以数组的形式存储和显示用户输入

我试图显示并打印用户的一个单词并将其存储到我调用的数组中

char word[20]
Run Code Online (Sandbox Code Playgroud)

但我遇到了麻烦.我知道我们使用"for循环"将其扫描到阵列中,但我继续在圈子里进行,我相信问题在于i < 20.我对此进行了研究,发现对此的答案非常有经验,我需要一种非常基本的方法来做到这一点而不需要额外的东西.所以我想要的是从用户那里得到消息,存储它并将其打印到屏幕上.

没有经验的代码可以帮助吗

C中的代码

char getWord(char word[]);
int main()
{   
    char word[20];  
    getWord(word);

    return 0;
}

char getWord(char word[])
{ 
    int i;
    printf("Enter a word: ");
    for (i = 0; i < 20; i++) 
    { 
        scanf(" %c", &word[i]);
    }

    return word;
}
Run Code Online (Sandbox Code Playgroud)

c arrays

0
推荐指数
1
解决办法
2689
查看次数

如何比较两个空的地址*

我有两个void *,即void *avoid *b.让我们说a是在0x804ae0b现在0x804aec.我该如何比较两者?我想检查地址a是否低于地址b.

c pointers

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

"错误:流浪'\ 342'","迷失'\'200'","迷失'\'213'"在C编译中

这是我的代码

int main()?
{
    float avg, age[] = { 23.4, 55, 22.6, 3, 40.5, 18 };
    avg = average(age); /* Only name of array is passed as argument. */
    printf("Average age=%.2f", avg);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译错误int main():

error: stray '\342' in program
error: stray '\200' in program
error: stray '\213' in program
Run Code Online (Sandbox Code Playgroud)

c

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

C编程语言中的素数在1到100之间

我想打印1到100之间的素数,我写下我的代码如下,但是当我运行它时,它开始打印3,7,11,17 .... 91为什么不打码2?请帮帮我的朋友

#include <stdio.h>
int main(void)
{
    for(int i=2;i<100;i++)
    {
        for(int j=2;j<i;j++)
        {
            if(i%j==0)
                break;
            else if(i==j+1)
                printf("%d\n",i);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c loops for-loop

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

标签 统计

c ×5

arrays ×1

c++ ×1

for-loop ×1

loops ×1

pointers ×1

stl ×1