EmbLogic's Blog

Plz Explain how to solve this question?

int main(){
    int a[]={10,20,30,40};
    int i=3,x;
    x=1*a[--i]+2*a[--i]+3*a[--i];
    printf(“%d”,x);
}

4 Responses to Plz Explain how to solve this question?

  1. rajnish says:

    x=100;
    initial value of i=3;
    after–i=2
    after–i=1
    after–i=0
    so the coresponding value is 30,20,10
    s0 x=1*30+2*20+3*10=100

  2. vinod khatana says:

    we can’t use more than one, pre or post increment in one line,according to standard its give warning when prog. compile from command “gcc -Wall que.c”.Its should as give bellow and o/p = 100;
    i=3;
    x = 1*a[--i];
    x = x+2*a[--i];
    x = x+3*a[--i];
    printf(“%d\n”,x);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>