这个:
int k=3;
printf("%d %d %d",k++,k,++k);
Run Code Online (Sandbox Code Playgroud)
提供输出,4 4 4因为它们被推入堆栈中:
%d%d%d
4 -- for k++
4 --for k
4 --for ++k
Run Code Online (Sandbox Code Playgroud)
对?
这个:
int k = 3;
cout << k++ << k << ++k;
Run Code Online (Sandbox Code Playgroud)
实际上是重复的函数调用,所以它相当于:
( ( (cout << k++) << k) << ++k);
Run Code Online (Sandbox Code Playgroud)
所以,我认为首先是k++再k然后++k必须按以下顺序执行的,对不对?我相信函数调用是一个序列点,但输出在不同的实现上有所不同.为什么会这样?
下面的代码汇编得很好
int a=5,b=4,c;
a>b?30:40;
Run Code Online (Sandbox Code Playgroud)
也是,
int a=5,b=4,c;
a>b?c=30:40;
Run Code Online (Sandbox Code Playgroud)
但为什么这不起作用?
int a=5,b=4,c;
a>b?c=30:c=40;
Run Code Online (Sandbox Code Playgroud) 你如何解释这里发生的舍入?我认为将浮点值赋给Int的总是会导致十进制后的值丢失?
int z=39.99999999999999999999999;
printf("%d",z); // gives 40
Run Code Online (Sandbox Code Playgroud)
谢谢
下面的代码有什么问题.对于某些输入和某些特殊输入的崩溃,它运行完全正常吗?
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
struct event {
string date,time,content;
bool is_high_priority;
};
int main() {
event one,two;
one.is_high_priority=false;
char tmp;
ofstream out_file("events" , ios::binary );
cout<<"\nEnter Date(dd.mm) ";
cin>>one.date;
cout<<"\nEnter Time(hh:mm:ss) ";
cin>>one.time;
cout<<"\nenter content";
cin>>one.content;
if(tmp == 't')
one.is_high_priority = true;
else
one.is_high_priority = false;
out_file.write((char*) &one, sizeof(one) );
out_file.close();
ifstream in_file("events" , ios::binary );
in_file.read((char*)&two,sizeof(two));
cout<<two.date<<" "<<two.time<<" "<<two.content<<" "<<two.is_high_priority;
in_file.close();
}
Run Code Online (Sandbox Code Playgroud)
它为这些输入而崩溃:输入日期(dd.mm)ankmjjdn md
输入时间(hh:mm:ss)输入contentsnjs sjnsn
为什么这样做
printf("Hello"
"World");
Run Code Online (Sandbox Code Playgroud)
而
printf("Hello
""World");
Run Code Online (Sandbox Code Playgroud)
才不是?ANSI C连接相邻的字符串,没关系......但这是另一回事.这与C语言解析器有什么关系吗?谢谢
我有一个JAVA方法,它可以返回基类的实例(Say A)或派生类的实例(比如B),具体取决于运行时输入.(B来自A)
现在,在方法返回类型为"B"的对象的情况下,如何将其分配给类型为"B"的引用?我不能只将它分配给基类型的引用,因为我需要使用仅在派生类中的成员.
有没有办法在不使用 NIO 的情况下递归地在路径上设置 777 权限(以便路径上的所有目录都获得 777 权限)。
我们可以通过文件类中的方法为给定文件的最后一个叶子做这件事,如下所示
import java.io.File;
import java.nio.file.FileSystems;
public class permissionTest {
public static void main(String [] args){
String dir = "./leaf1/leaf2/leaf3";
File baseDir = new File(dir);
boolean success = baseDir.mkdirs();
if (success) {
System.out.println("Created dirs");
baseDir.setExecutable(true, false);
baseDir.setReadable(true, false);
baseDir.setWritable(true, false);
}
else{
System.out.println("Not created");
}
}
}
Run Code Online (Sandbox Code Playgroud)
上面给了 777 给 Leaf3 ,如何给 777 给 Leaf1 & Leaf2 呢?在单个命令中?
c ×4
c++ ×2
java ×2
777 ×1
crash ×1
glibc ×1
grammar ×1
inheritance ×1
permissions ×1
polymorphism ×1
printf ×1
return-type ×1
rounding ×1
scanf ×1
syntax ×1