[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]


    Search the Q&A Archives


#include<stdio.h> main() { int i=4; i= i++ * ++i; ...

<< Back to: comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ)

Question by sasmendra
Submitted on 2/25/2004
Related FAQ: comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ)
Rating: Rate this question: Vote
#include<stdio.h>
main()
{
int i=4;
i= i++ * ++i;
printf("%d",i);
}


Answer by TXH1138
Submitted on 3/19/2004
Rating:  Rate this answer: Vote
This is not defined.

 

Answer by saran
Submitted on 5/12/2004
Rating:  Rate this answer: Vote
answer is 26

 

Answer by harish
Submitted on 5/12/2004
Rating:  Rate this answer: Vote
this is compiler dependent

 

Answer by Amit
Submitted on 6/7/2004
Rating:  Rate this answer: Vote
The answer for ANSI compliant compilers is 26, because unary operators do in-place increment/decrement of values, so when ++i is encountered value of i is raised by 1 and is reflected at both occurrences of i (ie., i++ & ++i) so the value of expression is 25 which is post incremented to 26, hence the answer.

 

Answer by chiru-k
Submitted on 6/10/2004
Rating:  Rate this answer: Vote
yea, answer(26) by saran is correct.

 

Answer by D00zer
Submitted on 9/19/2004
Rating: Not yet rated Rate this answer: Vote
Java makes that 24..

 

Answer by san
Submitted on 11/11/2004
Rating: Not yet rated Rate this answer: Vote
Sol}-is 30
        as i=4
        Then
        i++
       4+1
ans store in i
that is 5 then
        ++i
        i=5
        5+1 =6
        6*5=30
        is right



 

Answer by jiffin joy
Submitted on 11/25/2004
Rating: Not yet rated Rate this answer: Vote
24 (4*6)

 

Answer by vagninu
Submitted on 1/21/2005
Rating: Not yet rated Rate this answer: Vote
on gcc 3.3.4 answer is 25

 

Answer by vagninu
Submitted on 1/21/2005
Rating: Not yet rated Rate this answer: Vote
on gcc 3.3.3 answer is 26

 

Answer by l.gnanasekar
Submitted on 1/29/2005
Rating: Not yet rated Rate this answer: Vote
Ya, the answer is same as by amit.
int i=4;
i=i++ * ++i;
  the expression is executed in left to right. so the first i is postincremented and next is preincrement, it increment first and assign value here in that address the value is changed as 5 so botn place 5 like, 5 * 5 as calculated and another one postincremt is waiting so that increment as 26.

 

Answer by S
Submitted on 3/10/2005
Rating: Not yet rated Rate this answer: Vote
#include<stdio.h>

struct sPoint{
   float x;
            float y;
};

struct sVector{
   float x;
   float y;
};

void SetPoint(struct sPoint *,float, float);
void SetVector(struct sVector *, float, float);
void Translate1(struct sPoint *, struct sVector const*);
struct sPoint Translate2(struct sPoint ,struct sVector);
struct sPoint Translate3(struct sPoint , float, float);
void Translate4(float *, float *, float, float);

void main(void)
{
   struct sPoint point;
   struct sVector vector;

   SetPoint(&point,12.0f,45.0f);
   SetVector(&vector,1.0f,1.0f);
   printf("Point: x=%f, y=%f\n",point.x,point.y);
   printf("Vector: x=%f, y=%f\n",vector.x,vector.y);
   Translate1(&point, &vector);
   printf("Point: x=%f, y=%f\n",point.x,point.y);
   point=Translate2(point,vector);
   printf("Point: x=%f, y=%f\n",point.x,point.y);
   point=Translate3(point,vector.x, vector.y);
   printf("Point: x=%f, y=%f\n",point.x,point.y);
   Translate4(&point.x, &point.y, vector.x, vector.y);
   printf("Point: x=%f, y=%f\n",point.x,point.y);
}

void SetPoint(struct sPoint *p, float x, float y)
{
   p->x=x;
   p->y=y;
}
void SetVector(struct sVector *v, float x, float y)
{
   v->x=x;
   v->y=y;
}


void Translate1(struct sPoint *p, struct sVector const *v)
{
   p->x+=v->x;
   p->y+=v->y;
}

struct sPoint Translate2(struct sPoint p,struct sVector v)
{
   p.x+=v.x;
   p.y+=v.y;
   return p;
}

struct sPoint Translate3(struct sPoint p,float x, float y)
{
   p.x+=x;
   p.y+=y;
   return p;
}

void Translate4(float *px, float *py, float vx, float vy)
{
   *px+=vx;
   *py+=vy;
}

 

Answer by icarokar
Submitted on 3/30/2005
Rating: Not yet rated Rate this answer: Vote
The answer is 26

 

Answer by aryan
Submitted on 10/19/2005
Rating: Not yet rated Rate this answer: Vote
answer is 12 .

 

Answer by eººeensiki
Submitted on 10/30/2005
Rating: Not yet rated Rate this answer: Vote
HE LA!
26 doğru amına çakıyım.

 

Answer by edmar sardinas``1
Submitted on 1/12/2006
Rating: Not yet rated Rate this answer: Vote
because a hard english to me & math algebra

 

Answer by Rassnitzer
Submitted on 1/17/2006
Rating: Not yet rated Rate this answer: Vote
The answer is 20 because i (register) is incremented before operation on ++i but is the last operation on i++ so:
i=i++*++i > i=4++ * ++4 > i = 4 (i is incremented after the whole operation) * 5 (i is incremented immediately and then 4*5 is applied to the "new" i; the i what was incremented is not the same i at the end (other register)

 

Answer by sthuthi
Submitted on 6/11/2006
Rating: Not yet rated Rate this answer: Vote
mande urs

 

Answer by sri
Submitted on 6/12/2006
Rating: Not yet rated Rate this answer: Vote
first it will consider the increment so i will become 5
i * i =25 then i++
so the output will be 26

 

Answer by sthuthi
Submitted on 6/17/2006
Rating: Not yet rated Rate this answer: Vote
syntax error

 

Answer by Arikt Jain
Submitted on 10/13/2006
Rating: Not yet rated Rate this answer: Vote
26 is the correct answer...ENJOY!!!

 

Answer by zwi
Submitted on 11/8/2006
Rating: Not yet rated Rate this answer: Vote
It is a special case of the following:
i=i++;
that is specified to be "undefined" in the standard

 

Answer by Ruwan Sampath Wickramathilaka
Submitted on 12/29/2006
Rating: Not yet rated Rate this answer: Vote
#include<stdio.h>
main()
{
int i=4;
i= i++ * ++i;
printf("%d",i);
}

 

Answer by Soumen Bag
Submitted on 1/31/2007
Rating: Not yet rated Rate this answer: Vote
26
Before performing multiplication first ++i will be executed, at the time of multiplication, the present value of i is 5.After multiplication present value of i is 25(5*5).Now i++ will be performed.So the final result will be i+1 that is 26...

 

Answer by misar
Submitted on 3/19/2007
Rating: Not yet rated Rate this answer: Vote
Hi
How can we do combination on C program?
see you!
thanks for your answers.

 

Answer by snake7co
Submitted on 4/5/2007
Rating: Not yet rated Rate this answer: Vote
28918273829101

 

Answer by MARY
Submitted on 5/17/2007
Rating: Not yet rated Rate this answer: Vote
#include<stdio.h>
{
   char nom[30];
   int DNI,
      printf("ingrese nombre\n")
      scanf("%s",nom);
   printf("ingrese DNI\n");
   scanf("%d",&DNI);
   printf("%s%d",nom,DNI);
   return 0,
}

 

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.


Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

 

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.

 

<< Back to: comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ)


[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.