小编cha*_*rre的帖子

混合数据类型(int,float,char等)如何存储在数组中?

我想在数组中存储混合数据类型.怎么可能这样做?

c arrays

143
推荐指数
5
解决办法
4万
查看次数

为什么数组名称是指向数组第一个元素的指针?

总是这样,我的意思是,数组名称总是指向数组的第一个元素的指针.为什么它是这样的呢?它是实现有点事物还是语言特征?

c arrays pointers

8
推荐指数
2
解决办法
5295
查看次数

C-声明静态的函数的链接

声明为static的函数和变量具有内部链接,它们具有文件范围,并且对于其他文件中的函数不可见.

假设我声明了这样的函数: -

  static int foo(int i);
Run Code Online (Sandbox Code Playgroud)

在一个名为file1.c的文件中我可以通过使用指针从其他文件file2.c访问此函数.

我正在阅读一本书,其中写道它可以完成,但我不知道这是怎么可能的.

这些是确切的行: -

因为它具有内部链接,所以不能直接从定义它的文件外部调用foo.(将foo声明为静态并不能完全阻止它在另一个文件中被调用;通过函数指针的间接调用仍然是可能).

c static scope

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

从任何观点来看,++ i和i + = 1之间的区别是什么

这是kn king的c编程问题:一种现代的方法.我无法理解他给出的解决方案: -

The expression ++i is equivalent to (i += 1). The value of both expressions is i after 
the increment has been performed.
Run Code Online (Sandbox Code Playgroud)

我怎么理解这个呢?

c operators

4
推荐指数
2
解决办法
3万
查看次数

函数生成器与Python 3中的类生成器

为什么函数发生器和类生成器的行为不同?我的意思是,使用类生成器,我可以根据需要多次使用生成器,但是使用函数生成器,我只能使用它一次?为什么这样?

def f_counter(low,high):
    counter=low
    while counter<=high:
        yield counter
        counter+=1

class CCounter(object):
    def __init__(self, low, high):
        self.low = low
        self.high = high
    def __iter__(self):
       counter = self.low
       while self.high >= counter:
            yield counter
            counter += 1

f_gen=f_counter(5,10)
for i in f_gen:
    print(i,end=' ')

print('\n')

for j in f_gen:
    print(j,end=' ')  #no output

print('\n')

c_gen=CCounter(5,10)
for i in c_gen:
    print(i,end=' ') 

print('\n')

for j in c_gen:
    print(j,end=' ')
Run Code Online (Sandbox Code Playgroud)

python generator python-3.x

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

在代码中这里做什么?

在下面的代码中,while循环是做什么的(用"loop"标记)?: -

int main(void)
{
    char code;

    for (;;)
    {
        printf("Enter operation code: ");
        scanf(" %c", &code);
        while (getchar() != '\n')   // loop
            ;
        switch (code)
        {
        case 'i':
            insert();
            break;
        case 's':
            search();
            break;
        case 'u':
            update();
            break;
        case 'p':
            print();
            break;
        case 'q':
            return 0;
        default:
            printf("Illegal code\n");
        }
        printf("\n");
    }
}
Run Code Online (Sandbox Code Playgroud)

Diclaimer:代码不完整,它只是代码的一部分,因为它不能编译.

c loops

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

如何在 ubuntu 16.04 上安装适用于 python3 selenium 的 firefoxdriver webdriver?

我在 Ubuntu 16.04 上安装了 python3-selenium apt 包。安装时,收到一条消息:

Suggested packages:
chromedriver firefoxdriver
The following NEW packages will be installed:
python3-selenium
Run Code Online (Sandbox Code Playgroud)

当我尝试运行以下 python 代码时,

#! /usr/bin/python3.5
from selenium import webdriver
import time

def get_profile():
    profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.privatebrowsing.autostart", True)
    return profile

def main():
    browser = webdriver.Firefox(firefox_profile=getProfile())

    #browser shall call the URL
    browser.get("http://www.google.com")
    time.sleep(5)
    browser.quit()

if __name__ == "__main__":
    main()
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

回溯(最近一次调用最后一次):文件“./test.py”,第 19 行,在 main() 文件“./test.py”,第 11 行,在主浏览器 = webdriver.Firefox(firefox_profile=getProfile())文件“/usr/lib/python3/dist-packages/selenium/webdriver/firefox /webdriver.py”,第77行,在init self.binary中,超时),文件“/usr/lib/python3/dist-packages/selenium /webdriver/firefox/extension_connection.py”,第 47 行,在init self.profile.add_extension() 文件“/usr/lib/python3/dist-packages/selenium/webdriver/firefox/firefox_profile.py”,第 91 行,在add_extension self._install_extension(extension) 文件“/usr/lib/python3/dist-packages/selenium/webdriver/firefox/firefox_profile.py”,第 …

python selenium python-3.x selenium-webdriver python-3.5

3
推荐指数
1
解决办法
2万
查看次数

如何在不使用计数器的情况下检查数组的元素是否相同?

假设我有一个数组

 bool string[N]={false};
Run Code Online (Sandbox Code Playgroud)

在执行某些操作之后,数组字符串的所有元素都变为true.我想在if语句中检查这种情况,如下所示: -

伪代码 -

if(all the elements of string are same or equal)
 then do this
Run Code Online (Sandbox Code Playgroud)

我怎么做到这一点?我不应该使用像这样的计数器

for(int i=0;i<N;i++)   //or something else like this 
Run Code Online (Sandbox Code Playgroud)

c arrays comparison

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

为什么编译器会抱怨分配?

在编译以下代码时,编译器会生成警告:

赋值从指针目标类型中丢弃'const'限定符

#include<stdio.h>

int main(void)
{
 char * cp;
 const char *ccp;
 cp = ccp;
}
Run Code Online (Sandbox Code Playgroud)

这段代码还可以(没有警告).为什么?

#include<stdio.h>

int main(void)
{
 char * cp;
 const char *ccp;
 ccp = cp;
}
Run Code Online (Sandbox Code Playgroud)

编辑:那为什么不行呢?

int foo(const char **p) 
{ 
  // blah blah blah ...
}

int main(int argc, char **argv)
{
 foo(argv);
}
Run Code Online (Sandbox Code Playgroud)

c variable-assignment

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

两个If表达式之间的区别?

以下是什么区别: -

  if(source[i] != ' ' && source[i+1] != ' ')        //1
Run Code Online (Sandbox Code Playgroud)

  if(!( source[i] == ' ' && source[i+1] == ' '))     //2
Run Code Online (Sandbox Code Playgroud)

c if-statement

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