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       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
1)
int i=5;
j=i++ + i++ + i++;
printf("%d",j);This code gives the answer 15.But if we 
replace the value of the j then anser is different?why?

2)int i=5;
printf("%d",i++ + i++ + i++);
this givs 18.
 Question Submitted By :: Kaduchandrakant
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18.
Answer
# 1
in the 1st case post increment will be done at the end of
the statement that is 15 is assigned to 'j' then 'i' will
increment 3 times bcoz 3 post increments r there.
    in the later case first 15 assign to 'i' then increment
3 times and assign to 'i'
 
Is This Answer Correct ?    3 Yes 4 No
Divakar
 
  Re: 1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18.
Answer
# 2
Remember increment operator is compiler depended.
1.
     if u compiled in TC++ then u will get j=18
     if u compile in VC++ then u will get j=15.   
2.   
     if u compiled in TC++ then u will get j=18
     if u compile in VC++ then u will get j=15.
 
Is This Answer Correct ?    2 Yes 5 No
Satyasaran
 
 
 
  Re: 1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18.
Answer
# 3
I have tried the second case in linux with gcc. But, the
output is 15 and not 18.
 
Is This Answer Correct ?    2 Yes 2 No
Gireesh
 
  Re: 1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18.
Answer
# 4
in the 1st case post increment will be done at the end of
the statement that is 15 is assigned to 'j' then 'i' will
increment 3 times bcoz 3 post increments r there.
    in the later case first 15 assign to 'i' then increment
3 times and assign to 'i'
 
Is This Answer Correct ?    1 Yes 1 No
Amey
 
  Re: 1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18.
Answer
# 5
both the codes possess undefined behaviour because the value
of i is changing more than once between two sequence points...

hence my answer is undefined behaviour
 
Is This Answer Correct ?    4 Yes 0 No
Prasoon
 
  Re: 1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18.
Answer
# 6
In the first case 
 initially j=15 is assigned that is (5+5+5).then i gets incremented thrice.if we try to print i then i will be
 8 (5 is incremented thrice).

In the second case
 as we know that printf gets evaluated 4m right to left
  that is  pf("%d", 5++ + 5++ +5++);
  that means  4m right to left  7+6+5=18
 firstly i's value is 5 then it gets incremented 6 then 7.
 
Is This Answer Correct ?    1 Yes 0 No
Raghu
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
main() { if (!(1&&0)) { printf("OK I am done."); } else { printf("OK I am gone."); } } a. OK I am done b. OK I am gone c. compile error d. none of the above HCL1
void main() { printf(“sizeof (void *) = %d \n“, sizeof( void *)); printf(“sizeof (int *) = %d \n”, sizeof(int *)); printf(“sizeof (double *) = %d \n”, sizeof(double *)); printf(“sizeof(struct unknown *) = %d \n”, sizeof(struct unknown *)); }  1
1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above declarations.  2
How to reverse a String without using C functions ? Wipro14
typedef struct error{int warning, error, exception;}error; main() { error g1; g1.error =1; printf("%d",g1.error); }  1
main() { int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf(" %d ",*c); ++q; } for(j=0;j<5;j++){ printf(" %d ",*p); ++p; } }  1
How to read a directory in a C program?  4
main() { char *p; p="%d\n"; p++; p++; printf(p-2,300); }  1
void pascal f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } void cdecl f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } main() { int i=10; f(i++,i++,i++); printf(" %d\n",i); i=10; f(i++,i++,i++); printf(" %d",i); }  1
Finding a number multiplication of 8 with out using arithmetic operator NetApp8
How can u say that a given point is in a triangle? 1. with the co-ordinates of the 3 vertices specified. 2. with only the co-ordinates of the top vertex given.  1
Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba. You can assume that all the characters will be unique. Microsoft4
main() { int a=10,*j; void *k; j=k=&a; j++; k++; printf("\n %u %u ",j,k); }  1
main() { clrscr(); } clrscr();  1
Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list) Disney3
Link list in reverse order. NetApp7
int swap(int *a,int *b) { *a=*a+*b;*b=*a-*b;*a=*a-*b; } main() { int x=10,y=20; swap(&x,&y); printf("x= %d y = %d\n",x,y); }  1
What are the following notations of defining functions known as? i. int abc(int a,float b) { /* some code */ } ii. int abc(a,b) int a; float b; { /* some code*/ }  1
String copy logic in one line. NetApp9
How will you print % character? a. printf(“\%”) b. printf(“\\%”) c. printf(“%%”) d. printf(“\%%”) HCL1
 
For more C Code 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