main() { int a[3][3]={{1,2,3},{4,5,6},{7,8,9}}; int *b; b=a; printf("%d",a[1][1]); printf("%d",b) }main(){ int a[3][3]={{1,2,3},{4,5,6},{7,8,9}};int *b;b=a;printf("%d",a[1][1]);printf("%d",b[1][1]);为什么printf("%d",a[1][1]);能运行,而且b=a也

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 00:33:27
main(){inta[3][3]={{1,2,3},{4,5,6},{7,8,9}};int*b;b=a;printf("%d",a[1][1]);printf("%d",b)}main(){int

main() { int a[3][3]={{1,2,3},{4,5,6},{7,8,9}}; int *b; b=a; printf("%d",a[1][1]); printf("%d",b) }main(){ int a[3][3]={{1,2,3},{4,5,6},{7,8,9}};int *b;b=a;printf("%d",a[1][1]);printf("%d",b[1][1]);为什么printf("%d",a[1][1]);能运行,而且b=a也
main() { int a[3][3]={{1,2,3},{4,5,6},{7,8,9}}; int *b; b=a; printf("%d",a[1][1]); printf("%d",b) }
main()
{ int a[3][3]={{1,2,3},{4,5,6},{7,8,9}};
int *b;
b=a;
printf("%d",a[1][1]);
printf("%d",b[1][1]);
为什么printf("%d",a[1][1]);能运行,而且b=a也能运行,但是printf("%d",b[1][1]);就不呢不运行
}
为什么改为int (*b)[3]就可以了?下表运算符是什么?而且printf("%d",b[0][0])也不行
经过我的实验,原来a和b值是一样的,只不过他们的机制不一样,a+1则a[1]的地址,而b+1则为a[0][1]地址,所以上面的就不对了.

main() { int a[3][3]={{1,2,3},{4,5,6},{7,8,9}}; int *b; b=a; printf("%d",a[1][1]); printf("%d",b) }main(){ int a[3][3]={{1,2,3},{4,5,6},{7,8,9}};int *b;b=a;printf("%d",a[1][1]);printf("%d",b[1][1]);为什么printf("%d",a[1][1]);能运行,而且b=a也
把b的定义改为,int (*b)[3]就可以了
定义成这样子,说明b是一个指向一个长度为3的一维数组,也就是书上所说的行指针.意思是,b+1,就指向了a[1],一下子跳过了a[0](一共六个字节),而不是指向a[0][1];
你本来把b定义成int *b;则这个是列指针,即一次只移动一个int
的长度(两个字节).所以此时的b+1,就指向了a[0][1];

#include int a=3,b=5; max (int a,int b) {int c; c=a>b?a:b; return (c); } void main() {int #include using namespace std; int main() { int a,b,c; a=3; int f(int x,int y,int z);#include using namespace std; int main() {int a,b,c;a=3;int f(int x,int y,int z); cin>>a>>b>>c;c=f(a,b,c);cout void main() {int t=1;fun(fun(t));} fun(int h) {stvoid main(){int t=1;fun(fun(t));}fun(int h){static int a[3]={1,2,3}; int k; for(k=0;k main() {int t=1;fun(fun(t));} fun(int h){static int a[3]={1,2,3};int k; for(k=0;k #include int b=2; int fun(int *k) {b=*k+b;return(b);} main() {int a[10]={1,2,3,4,5,6,7,8}, C++题目看不懂,结果是怎么算出来的,#includeusing std::cin;using std::cout;using std::endl;float f1(int);float f2(int);double twice(float (*)(int),int);int main(){int a=3;int b=5;cout main() { int a,b,c; a=1;b=2;c=3; if(a int fm(int a,int b) {if(b==1)return a; else return a+fm(a,b-1); } main( ) { printf(%d ,fm(4,3)) int fm(int a,int b) {if(b==1)return a; else return a+fm(a,b-1); } main( ) { printf(%d ,fm(4,3) int a=3; main(){int s=0;{int a=5;s+=a++;}s+=a++;printf(%d ,s);} #include void main(){ int b=3;int a; int arr[]={6,7,8,9,10}; int *ptr=arr; *(ptr++)+=123;#include using namespace std;void main(){ int b=3;int a; int arr[]={6,7,8,9,10}; int *ptr=arr; *(ptr++)+=123; printf(%d,%d ,*(p #include int b=2; int fun(int*k) { b=*k+b;return(b);} main() {int a[10]={1,2,3,4,5,6,7,8}#include int b=2; int fun(int*k) { b=*k+b;return(b);} main() {int a[10]={1,2,3,4,5,6,7,8},i;for(i=2;i void fun(int a,int b) { int t; t=a;a=b;b=t; } main()void fun(int a,int b){ int t; t=a;a=b;b=t; } main() { int c[10]={1,2,3,4,5,6,7,8,9,0}.i; for(i=0;i public class Test{ public static void main(String args[]){ int i=1,b,c; int[] a=new int[3]; b=a[i]; 矩阵相加(C++)#include using namespace std; const int rows=3;const int cols=3;void matrixadd(int *,int *,int *,int,int);int main(){int a[rows][cols]={{1,3,5},{7,8,11},{13,15,17}};int b[rows][cols]={{9,8,7},{6,5,4},{3,2,1}};int c[rows][cols]={0 #include int call(int s[],int y) { static int t=3; y=s[t--]; return(y); } void main() { in#includeint call(int s[],int y){static int t=3;y=s[t--];return(y);}void main(){int a[]={3,8,4,2},n,x=0;for(n=0;n #include int f1(int a,int b)15,9 { int c; c=b%2; return a+c; }int f2(int a,int b){ int c;a+=a;b+=b;c=f1(a+b=14,++b9);return c;}void main(){ int a=3,b=4;cout #include void main() { int a[3][3],i,j; for(i=0;i