我们可以像这样声明一个类成员:
class Test {
public:
int a;
}
Run Code Online (Sandbox Code Playgroud)
这就是我们如何声明,但我想知道变量a的定义.
我知道静态类成员,它是静态变量所以它不能在类中定义,它应该在类外定义.所以我认为普通的类成员应该有一个定义的位置,我猜它是隐式定义普通成员的构造函数.是对的吗?
我写这篇文章是为了好玩:
#include <iostream>
#include <cstdlib>
using namespace std;
int Arsenal = rand()%3;
int Norwich = rand()%3;
int main () {
if (Arsenal > Norwich) {
cout << "Arsenal win the three points, they are in the Top Four";
return 0;
} else if (Arsenal == Norwich) {
cout << "The game was a draw, both teams gained a point";
return 0;
} else (Norwich > Arsenal) {
cout << "Norwich won, Arsenal lost";
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试用g ++编译它,但我得到这个错误:
arsenalNorwich.cpp: …Run Code Online (Sandbox Code Playgroud) ISO/IEC 9899:2011§5.2.4.2.210(p48)说:
是否存在次正规数的特征是FLT_HAS_SUBNORM,DBL_HAS_SUBNORM和LDBL_HAS_SUBNORM的实现定义值:
-1不确定
0缺席(类型不支持次正规数)
1存在(类型支持次正规数)
什么了!所以在某些平台上我不能写double d = 33.3?或者编译器会自动将其转换为333E-1?存在或不存在非标准化浮点数的实际意义是什么?
我执行这样的命令
echo 'int main(){printf("%lu\n",sizeof(void));}' | gcc -xc -w -&& ./a.out
Run Code Online (Sandbox Code Playgroud)
并且可以得到结果:1.但我无法找到 - &&的意思,甚至在搜索手册页和谷歌之后!并且我尝试在没有 - && option.it的情况下执行它将是这样的错误:
./a.out:1: error: stray ‘\317’ in program
./a.out:1: error: stray ‘\372’ in program
./a.out:1: error: stray ‘\355’ in program
./a.out:1: error: stray ‘\376’ in program
./a.out:1: error: stray ‘\7’ in program
./a.out:1: error: stray ‘\1’ in program
./a.out:1: error: stray ‘\3’ in program
./a.out:1: error: stray ‘\200’ in program
./a.out:1: error: stray ‘\2’ in program
./a.out:1: error: stray ‘\16’ in program
./a.out:1: error: expected identifier …Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
int main(void)
{
char ch;
//character = ch
printf("Please type a character [A-Z or a-z] ('x'to exit):");
scanf("%c", &ch);
switch(ch) //switch statement
{
case 'a':
printf("%c is a vowel.\n", ch);
break;
case 'e':
printf("%c is a vowel.\n", ch);
break;
case 'i':
printf("%c is a vowel.\n", ch);
break;
case 'o':
printf("%c is a vowel.\n", ch);
break;
case 'u':
printf("%c is a vowel.\n", ch);
break;
case 'A':
printf("%c is a vowel.\n", ch);
break;
case 'E':
printf("%c is a vowel.\n", ch); …Run Code Online (Sandbox Code Playgroud) 所以,我知道小梅提供了两个余数运营商,rem和mod,但究竟什么是它们之间的区别?我能够找到这个,但我不确定我是否完全掌握了这一点.
我的bash版本是:
bash --version
GNU bash, version 4.2.45(1)-release (x86_64-pc-linux-gnu)
Run Code Online (Sandbox Code Playgroud)
如果我做原型功能
#!/bin/bash
function f()
{
echo "hello" $1
}
f "world"
Run Code Online (Sandbox Code Playgroud)
我明白了 Syntax error: "(" unexpected
这是为什么?
shopt的输出是:
autocd off
cdable_vars off
cdspell off
checkhash off
checkjobs off
checkwinsize on
cmdhist on
compat31 off
compat32 off
compat40 off
compat41 off
direxpand off
dirspell off
dotglob off
execfail off
expand_aliases on
extdebug off
extglob on
extquote on
failglob off
force_fignore on
globstar off
gnu_errfmt off
histappend on
histreedit off
histverify off
hostcomplete off …Run Code Online (Sandbox Code Playgroud) 我知道指针通常在声明时分配,但我想知道是否有任何方法可以在C中创建一个全局指针.例如我的代码如下:这是一个好习惯吗?
static int *number_args = NULL;
void pro_init(int number)
{
number_args = &number; /* initialize the pointer value -- is this okay? */
}
Run Code Online (Sandbox Code Playgroud) 我有这个错误很奇怪:
/tmp/ccq0e479.o:main.c:(.text+0x1a): undefined reference to
`ft_putchar' collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
main.c:
#include "biblio.h"
int main(int argc, char** argv){
ft_putchar(argv[1]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
ft_putchar.c:
#include <stdio.h>
#include "biblio.h"
void ft_putchar (char* str){
int i = 0;
while (str[i] != '\0'){
write(1,str[i], 1);
i++;
}
write(1,'\0', 1);
}
Run Code Online (Sandbox Code Playgroud)
biblio.h
#ifndef biblio_ft
#define biblio_ft
void ft_putchar(char*);
#endif
Run Code Online (Sandbox Code Playgroud)