我正在通过Daniel liang在第9章"字符串"中介绍"Java编程第9版"来学习Java我遇到过这段代码:
public static int hexCharToDecimal(char ch){
if (ch >= 'A' && ch <= 'F')
return 10 + ch - 'A';
else
return ch - '0';
}
Run Code Online (Sandbox Code Playgroud)
oki所以有人可以解释刚刚发生在这里的事情吗?如何添加,整数中的子字符以及它背后的含义是什么,谢谢.
你好伙计们,我在这里有点新鲜,而且我也一直在练习函数指针,我已经想出了这段代码:
#include <stdio.h>
#include <stdlib.h>
typedef int (*fptr)(int,int);
void swapp(int*,int*);
int sub(int ,int );
int add(int ,int );
int operation(fptr,int,int);
int main()
{
int n=10,n1=25;
printf("%d+%d=%d",n,n1,compute(add,n,n1));
printf("\n%d-%d=%d",(n>n1)?n:n1,(n<n1)?n:n1,compute(sub,n,n1));
return 0;
}
void swapp(int *a,int *b){
int temp=*a;
*a=*b;
*b=temp;
}
int add(int a,int b){
return a+b;
}
int sub(int a,int b){
if(a<b)
swapp(a,b);
return a-b;
}
int compute(fptr operation ,int a,int b){
return operation(a,b);
}
Run Code Online (Sandbox Code Playgroud)
编译时我得到"分段错误(核心欺骗)任何人都可以帮助我调试这个?而且我只是看不出代码有什么问题