例如:
sizeof(char*)
返回4一样int*
,long long*
,我已经竭尽所能.这有什么例外吗?
我在linux框中搜索并看到它是typedef
typedef __time_t time_t;
Run Code Online (Sandbox Code Playgroud)
但找不到__time_t定义.
我正在从Java过渡到C++,并对long
数据类型有一些疑问.在Java中,要保存大于2 32的整数,您只需编写long x;
.但是,在C++中,它似乎long
既是数据类型又是修饰符.
似乎有几种使用方法long
:
long x;
long long x;
long int x;
long long int x;
Run Code Online (Sandbox Code Playgroud)
此外,似乎有一些事情,如:
long double x;
Run Code Online (Sandbox Code Playgroud)
等等.
所有这些不同的数据类型之间有什么区别,它们都有相同的目的吗?
我正在学习C编程语言,我刚开始用指针学习数组.我在这个问题上有问题,我希望输出必须是5
但是2
,有人可以解释原因吗?
int main(){
int arr[] = {1, 2, 3, 4, 5};
char *ptr = (char *) arr;
printf("%d", *(ptr+4));
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我试图来计算1 + 1 * 2 + 1 * 2 * 3 + 1 * 2 * 3 * 4 + ... + 1 * 2 * ... * n
,其中n
是用户输入.它适用于中值n
高达12.我要计算总和n = 13
,n = 14
和n = 15
.我如何在C89中做到这一点?据我所知,我unsigned long long int
只能在C99或C11中使用.
我的代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned long int n;
unsigned long int P = 1;
int i;
unsigned long int sum = …
Run Code Online (Sandbox Code Playgroud) 我在Windows和Mac上运行完全相同的代码,使用python 3.5 64位.
在Windows上,它看起来像这样:
>>> import numpy as np
>>> preds = np.zeros((1, 3), dtype=int)
>>> p = [6802256107, 5017549029, 3745804973]
>>> preds[0] = p
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
preds[0] = p
OverflowError: Python int too large to convert to C long
Run Code Online (Sandbox Code Playgroud)
但是,此代码在我的Mac上运行正常.任何人都可以帮助解释为什么或为Windows上的代码提供解决方案?非常感谢!
我已经下载了MinGW-64,所以我现在可以使用g ++ 4.7.0(实验性)编译适用于Windows 7的64位程序.但是以下行:
cout << sizeof(long) << " " << sizeof(void*) << endl ;
Run Code Online (Sandbox Code Playgroud)
打印4 8
,而不是8 8
.g ++ 4.6.0的文档说:
64位环境将int设置为32位,将long设置为64位
有谁知道为什么sizeof(long)
不是8?
编辑添加:我的困惑的来源是64位Windows的g ++ 4.7.0(还)是GNU编译器集合的官方部分.它是第一个带有32位的64位版本long
,因此文档根本不适用于它.实际上,如果您访问相关网页,IA-32/x86-64的完整条目包括:
...
我试图找到数字x的最大素数因子,Python给出了范围太大的错误.我尝试过使用x range但是我得到一个OverflowError:Python int太大而无法转换为C long
x = 600851475143
maxPrime = 0
for i in range(x):
isItPrime = True
if (x%i == 0):
for prime in range(2,i-1):
if (i%prime == 0):
isItPrime = False
if (isItPrime == True):
if (i > maxPrime):
maxPrime = i;
print maxPrime
Run Code Online (Sandbox Code Playgroud) 我正在对一些python代码进行基准测试,我注意到了一些奇怪 我使用以下函数来测量迭代空for循环所需的速度:
def f(n):
t1 = time.time()
for i in range(n):
pass
print(time.time() - t1)
Run Code Online (Sandbox Code Playgroud)
f(10**6)
打印about 0.035
,f(10**7)
about 0.35
,f(10**8)
about 3.5
和f(10**9)
about 35
.但是f(10**10)
?好吧2000
.这当然是意料之外的.为什么迭代10倍的元素需要花费60倍的时间?什么是python的for循环导致这个?这是特定于python的,还是会出现在很多语言中?
c ×5
c++ ×3
long-integer ×2
pointers ×2
python ×2
64-bit ×1
arrays ×1
benchmarking ×1
c89 ×1
for-loop ×1
int ×1
largenumber ×1
linux ×1
memory ×1
performance ×1
python-3.x ×1
range ×1
sizeof ×1
types ×1
windows ×1