我有以下结构和"getter"函数,它返回a强制转换为无符号整数:
struct s {
uint32_t a;
};
void get_a(struct s *st, unsigned *ret)
{
*ret = (unsigned)st->a;
}
Run Code Online (Sandbox Code Playgroud)
运行以下代码:
struct s st;
uint16_t x;
st.a = 1;
get_a(&st, (unsigned *)&x);
Run Code Online (Sandbox Code Playgroud)
对于x86_64,i686,armv7hl,ppc64le等架构x == 1,但对于ppc64 x == 0.为什么是这样?Little-vs. big-endian?
我想创建一个函数来分配(带malloc/ calloc)声明为双指针的矩阵.我理解双指针矩阵如何工作以及如何分配它malloc,但当我传递我的矩阵(声明main()并初始化NULL)时,我的程序崩溃了.我想错误与我的allocMatrix()功能有关,因为如果我在main所有工作中顺利分配矩阵.谢谢 :-)
主要:
#include <stdio.h>
#include <stdlib.h>
#include "Data.h"
#define ROW 5
#define COL 5
int main(void) {
int i,j, ret;
int nRow, nCol;
int **mat=NULL; // double pointer matrix
nRow = 0;
nCol = 0;
//Insert n of row and columns
printf("Insert n of rows and columns:\n");
scanf("%d %d", &nRow, &nCol);
//Functions to allocate matrix
ret=allocMatrix(mat, nRow, nCol);
printf("Return value: %d\n",ret);
/*
this code works …Run Code Online (Sandbox Code Playgroud) 我试图编写自己的atoi()函数实现,并尝试了两个不同的代码:
#include <stdio.h>
#include <string.h>
int myatoi(const char *string);
int main(int argc, char* argv[])
{
printf("\n%d\n", myatoi("str"));
getch();
return(0);
}
int myatoi(const char *string){
int i;
i=0;
while(*string)
{
i=(i<<3) + (i<<1) + (*string - '0');
string++;
// Don't increment i!
}
return i;
}
Run Code Online (Sandbox Code Playgroud)
和
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int x;
gets(str);
printf("%d",myatoi(str));
}
int myatoi(char *str) {
int res =0;
int i;
for (i = 0; str[i]!= '\0';i++) {
res = …Run Code Online (Sandbox Code Playgroud) 我有一个六列的pandas数据框,前三列包含x,y和z参考坐标,接下来的三列是某个点的坐标。我想将这两点之间的欧几里得距离放在数据框的新列中。我考虑使用numpy.linalg.normvia pandas.apply方法,但是我不知道解析numpy函数的数据帧行的最佳方法是什么。你能给我一些建议吗?
最近我参加了一次采访,有几个问题,我必须找到代码中的缺陷.以下是问题.
void fun(char *p)
{
int a = 0;
int b = strlen(p) - 1;
int d = 0;
while(d == 0)
{
if(a == b)
{
d = 1;
}
else
{
char t = *(p + a);
*(p + a) = *(p + b);
*(p + b) = t;
a += 1;
b -= 1;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的回答是:
NULL检查p. if(a == b).如果字符串的长度是偶数,则这种情况永远不会满足.如果有人发现任何其他缺陷,请告诉我,并且欢迎任何对我给出的答案的评论.
我有一个.txt包含列表的文件(这是列表的一个例子):
[[[[1155, 87]], [[1155, 612]], [[385, -81]], 0, 0, 0, 0, 0, 0, 0], [151, 130, 83, 0, 0, 0, 0, 0, 0, 0], [2, 4, 2, 0, 0, 0, 0, 0, 0, 0], [22, 31, 1, 0, 0, 0, 0, 0, 0, 0], [(1, 2, 3), (1, 2, 3), (1, 2, 3), 0, 0, 0, 0, 0, 0, 0], [[2, 3], [1, 3], [3], 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, …Run Code Online (Sandbox Code Playgroud)