C语言。指针在阵列和阵列 [英] C language. Pointer on array and array

查看:154
本文介绍了C语言。指针在阵列和阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帕斯卡尔:

type
    TA = packed record
        b: Char;    
        c: LongInt; 
    end;
    TAA = array[1..255] of TA;
var
    D: LongInt;
    Z: LongInt;
    N: array[0..10] of packed record
        F: LongInt;      
        Y: LongInt;          
        WL, WW: Word; 
        E: ^TAA;           
    end;    
var 
 b_var:char;
i,j:longint;
...
        b_var := N[i].E^[j].b;   

C语言:

typedef struct 
{
    char b;           
    signed long int c;
} TA;
typedef TA TAA[256]; 
signed long int D;
signed long int Z;
struct
{
    signed long int F;     
    signed long int Y;         
    unsigned int WL, WW;
    TAA *E;                  
} N[11];
...
//      b_var = N[i].*E[j].b;   /*is not allowed by compiler*/
//      b_var = N[i].(*E)[j].b; /*is not allowed by compiler*/
//      b_var = N[i].E[j]->b;   /*allowed by compiler, but no one knows is it same as Pascal */

这code不起作用。作品b_var = N [I] .E [J] - > B:
,但它是一样的帕斯卡code? E [j]为PTED为数组的元素或作为指针的元素?

This code does not work. Works b_var = N[i].E[j]->b; , but is it same as Pascal's code? E[j] is interpreted as element of array or as element of a pointer?

推荐答案

这是对数组指针的正确理解的 https://img-fotki.yandex.ru/get/53/240791000.0/0_17daa3_f02a9eaf_orig.png ?如果是正确的话b_var = N [I] * E [J] .B。和b_var = N [I] .E [J] - > B:不一样 。所以我应该做的,让帕斯卡尔逻辑是什么? -

Is it correct understanding of pointer on array https://img-fotki.yandex.ru/get/53/240791000.0/0_17daa3_f02a9eaf_orig.png ? If it is correct then b_var = N[i].*E[j].b; and b_var = N[i].E[j]->b; is not the same . So what should I do to keep Pascal logic? –

[]具有更高的优先级,然后解除引用。我思故我必须用b_var = N [I]。(* E)[J] .B ;.但在这种情况下,我得到了错误的语法错误:'(' -

[] has higher priority then dereference. I think I must therefore use b_var = N[i].(*E)[j].b;. But in this case I got error syntax error : '(' –

或者,也许我应该用b_var = N [I] .E [0] [J] .B; ?

Or maybe I should use b_var = N[i].E[0][j].b; ?

这篇关于C语言。指针在阵列和阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆