ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
main()
{
        int x=20,y=35;
        x = y++ + x++;
        y = ++y + ++x;
        printf("%d %d\n",x,y);
}
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 1
58
 
Is This Answer Correct ?    5 Yes 10 No
Guest
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 2
x=57
y=59
 
Is This Answer Correct ?    3 Yes 10 No
Mahendra Giri
 
 
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 3
57
59
 
Is This Answer Correct ?    2 Yes 7 No
Anjana
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 4
57
94
 
Is This Answer Correct ?    7 Yes 4 No
Preethi
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 5
55 

59
 
Is This Answer Correct ?    1 Yes 5 No
Chandan Dey
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 6
57 94
 
Is This Answer Correct ?    7 Yes 3 No
Rohit
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 7
57 94


{x=y++ + x++;}
equal to
{
x=y+x;//35+20
x++; //56
y++; //36
}


y=++y + ++x;
equal to
{
++y;//37
++x;//57
y=y+x;//37+57
}

So x=57
y=94
 
Is This Answer Correct ?    13 Yes 2 No
Jaya Prakash
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 8
while calculating the x value,x & y values are post 
incremented.So the values of x & y are added and then 
incremented i.e. x=56,y=36
while calculating the y value,x & y values are 
preincremtned,so x & y values are incremented and then 
added i.e. x=57,y=37.
so x=57
y=57+37=94.
 
Is This Answer Correct ?    9 Yes 2 No
Manju
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 9
x=57
y=94
 
Is This Answer Correct ?    8 Yes 3 No
Valli
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 10
55 59
 
Is This Answer Correct ?    1 Yes 8 No
Pooja
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 11
correct answer  is 57 94
 
Is This Answer Correct ?    4 Yes 4 No
Lucky
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 12
55  93
 
Is This Answer Correct ?    0 Yes 5 No
Vandana
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 13
Here this should make it easier for you...
                  
Problem_________|___Solution__|

int x=20, y=35;    (here the values of x,y are apparent.)

x = y++ + x++;     (x=y+x+1) or(x = 35 + 20 + 1)x  = 56
                   But; you incremented y, its now = 36

y = ++y + ++x;     (y =(y+1)+(x+1)) or(y=1+36+1+56)y = 94
                   This is the second time you incremented
                   x so it is now = 57. 


The reason that you are getting different increases
for x and y is that when you use statement(x=x++) you are 
first stating that x is = to x, and then 'increment x.
when you use statemnt(x=++x) you are first 
stating 'increment x, then that x is = to x.

look at the code and description in the chart below.

table:
code    =  meaning;
int x=2
int y=2
-------------------|
(x=x++) =  "x = x, x + 1" (increment happens after)
(x=++x) =  "x = (x+1)"    (increment happens before)
(x=y++) =  "x = y, y + 1" (increment happens after)
(x=++y) =  "x = (y+1)"    (increment happens before)

if you want to add y to x and then increment y use this 
statement:

x+=y++

if you want to increment y and then add it to x use this 
statement:

x+=++y
 
Is This Answer Correct ?    5 Yes 3 No
Joseph
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 14
Answer is 57 and 94
bcoz precedence of the ++ operator is more than + operator
so y++ and x++ will be evaluated first before addition so
y++ will be 36 and x++ will be 21 after that 36 + 21 = 57
similar reasoning for y = ++y + ++x
 
Is This Answer Correct ?    5 Yes 4 No
Ruchi
 
  Re: main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }
Answer
# 15
The program results in an undefined behaviour. You're wrong
if you have a certain answer. Learn more on the wikipedia
http://en.wikipedia.org/wiki/Sequence_point
 
Is This Answer Correct ?    3 Yes 0 No
Ledia
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
Write a program to interchange two variables without using the third variable? Accenture11
What are the commands should be given before weiting C Program i.e, Cd.. like Infonet3
which one of follwoing will read a character from keyboard and store in c a)c=getc() b)c=getchar() c)c=getchar(stdin) d)getc(&c) e)none  5
write the program for maximum of the following numbers? 122,198,290,71,143,325,98  4
How to convert a binary number to Hexa decimal number?? (Note:Do not convert it into binary and to Hexadecimal) Subex1
how to print a statement in c without use of console statement ,with the help of if statement it should print Satyam2
design and implement a program that reads floating-points numbers in a sentinel-controlled loop until the user terminates the program by entering zero.your program should determinate and print the smallest,largest and average of the supplied numbers.  1
what is a static function Satyam10
why the execution starts from main function  9
what is c? Tech-Mahindra5
User define function contain thier own address or not.  2
Write a program for deleting duplicate elements in an array Subex3
34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?  2
What is the diffences between Windows XP and Windows Visa Aricent1
what is the difference between declaration and definition of a variable or function ?  2
main() { float a=3.2e40; printf("%d",a); } Satyam5
5. What kind of sorting is this: SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort Accenture2
What is structure padding & expalain wid example what is bit wise structure?  1
What's the difference between a linked list and an array?  11
When is an interface "good"?  1
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com