UINT i,j;
i = j = 0;
i = ( i++ > ++j ) ? i++ : i--;

explain pls....

Answers were Sorted based on User's Feedback



UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls......

Answer / raj

1.we know that i=j=0 initially

2.then it will checks the non-incremented 'i' value(i.e 0)
with incremented 'j' value(i.e 1). So obviously condition
is falls.

3.now false statement has to be executed i.e (i--),before
executing this 'i' value is (i.e incremented value)'1'
after executing false condition(i.e i--)the value of 'i'
becomes '0'.

4.So the value of 'i' is '0'.

Is This Answer Correct ?    30 Yes 2 No

UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls......

Answer / vignesh1988i

UNIT i,j :
this line indicates that UNIT is an user defined data type. it may been declared as follows :

typedf int UNIT
we are making the code more readable

i=j=0 : indicates that the var. i and j are declared as 0

i=(i++>++j) ? i++ : i-- : the process here is

i++ is an post incrementation . if this is compared with any relational or any operaters first that value will be operated first and the 'i' will get incremented ........
but ++j if we take first thing it will increment the value and then operation will be performed

so when it is compared first i will be 0 and j will be 1 so 0 is not greater than 1. so false, so it will go to the statement after ':' so i-- is there so final value of i will be 0.

thank u

Is This Answer Correct ?    6 Yes 1 No

UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls......

Answer / dhatchina moorthy

r u guys nuts the person answered first is right.he
non-incremented 'i' value(i.e 0)
with incremented 'j' value(i.e 1). So condition
is falls.
so false part has to be executed i.e (i--),before
executing this 'i' value is (i.e incremented value)'1'
after executing false condition(i.e i-- her it doesn't
increment bcoz it is postfix operator)the value of 'i'
becomes '1'.

still having doubts, compile this program in ur pc.

Is This Answer Correct ?    5 Yes 1 No

UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls......

Answer / prem_mallappa

All answers are incorrect except this one.
Read c-faqs (Frequently asked questions about C)
The answer is unpredictable or implementation defined.

Is This Answer Correct ?    0 Yes 1 No

UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls......

Answer / chaneswara reddy

(i++ > j++) gives 0 because 0 > 0 is false so it return 0.
before returning 0 i is 1 ,but it is overwrite by 0.
In the Conditional operator false means ,it executes i++;
so i is 1.

Is This Answer Correct ?    3 Yes 19 No

Post New Answer

More C C++ Errors Interview Questions

what are the techniques for reducing the fragility of a memory bug?

1 Answers  


#include"stdio.h" #include"conio.h" void main() { int a; printf("\n enter a number:"); scanf("%c\n"); getch(); }

12 Answers   HCL,


what is macro in c? Difference between single linked list & double linked list what is fifo & lifo? what is stack & queue?

2 Answers   TCS,


void main() { int i=1; printf("%d%d%d",i,++i,i++); } Cau u say the output....?

24 Answers   HCL,


Write a program to accept two strings of Odd lengths. Then take all odd characters from one string and even characters from the other and concatenate and produce a string.

1 Answers  






#include<iostream.h> #include<stdlib.h> static int n=0; class account { int age,accno; float amt; char name[20]; public: friend void accinfo(account [] ,int); void create(); void balenq(); void deposite(); void withdrawal(); void transaction(account []); }; void account :: create() { static int acc=1231; accno=acc+n; cout<<"\n\tENTER THE CUSTOMER NAME : "; cin>>name; cout<<"\n\t ENTER THE AGE : "; cin>>age; cout<<"\n\t ENTER THE AMOUNT : "; cin>>amt; // if(amt<=500) // cout<<"\n\tAMOUNT IS NOT SUFFICIENT TO CREATE AN ACCOUNT..."; cout<<"\n\t YOUR ACCOUNT NUMBER : "<<accno<<endl; n++; } void accinfo(account cus[],int ch) { int no,flag=0; cout<<"\n\t\tENTER YOUR ACCOUNT NUMBER : "; cin>>no; for(int i=0;i<=n&&flag==0;i++) if(no==cus[i].accno) { flag=1; switch(ch) { case 2: cus[i].balenq(); break; case 3: cus[i].deposite(); break; case 4: cus[i].withdrawal(); break; case 5: cus[i].transaction(cus); break; default: cout<<"\n\t\tEND OF THE OPERATION"; exit(1); } } if(flag==0) cout<<"\n\t\tYOUR ACCOUNT DOES NOT EXIST..."<<endl; } void account :: balenq() { cout<<"\n\t\tCUSTOMER NAME : "<< name << endl; cout<<"\n\t\tBALANCE : "<< amt << endl; } void account :: deposite() { int damt; cout<<"\n\t\tCUSTOMER NAME : "<< name <<endl; cout<<"\n\t\tBALANCE : "<< amt <<endl; cout<<"\n\tENTER THE AMOUNT TO BE DEPOSITED : "; cin>>damt; amt+=damt; cout<<"\n\t\tYOUR CURRENT BALANCE : "<<amt<<endl; } void account :: withdrawal() { int wamt; cout<<"\n\t\tCUSTOMER NAME : "<< name; cout<<"\n\t\tBALANCE : "<< amt; cout<<"\n\tENTER THE AMOUNT TO BE WITHDRAWN : "; cin>>wamt; if(amt-wamt>=500) { amt-=wamt; cout<<"\n\t\tYOUR CURRENT BALANCE : "<<amt; } else cout<<"\n\tYOUR BALANCE IS TOO LOW FOR WITHDRAWAL..."<<endl; } void account :: transaction (account cus[]) { int no,tamt,flag=0; cout<<"\n\tENTER THE RECEIVER'S ACCOUNT NUMBER : "; cin>>no; cout<<"\n\t\t ENTER THE AMOUNT : "; cin>>tamt; for(int i=0;i<=n&&flag==0;i++) if(cus[i].accno==no) { flag=1; cus[i].amt+=tamt; amt-=tamt; cout<<"\n\t\tYOUR CURRENT BALANCE : "<<amt<<endl; cout<<"\n\t\t RECEIVER'S BALANCE : "<<cus[i].amt<<endl; } if(flag==0) cout<<"\n\tRECEIVER'S ACCOUNT NUMBER IS NOT AVALIABLE..."<<endl; } void main() { account cus[10]; int ch; do { cout<<"\n\t\t BANK ACCOUNT"; cout<<"\n\t\t ************\n"; cout<<"\n\t\t1.CREATE AN ACCOUNT"; cout<<"\n\t\t2.BALANCE ENQUIRY"; cout<<"\n\t\t3.DEPOSITE"; cout<<"\n\t\t4.WITHDRAWAL"; cout<<"\n\t\t5.TRANSACTION"; cout<<"\n\t\t6.EXIT\n\n"; cout<<"\n\t\tENTER YOUR CHOICE : "; cin>>ch; if(ch==1) cus[n].create(); else accinfo(cus,ch); }while(1); }

1 Answers  


How to develop a program using C language to convert 8-bit binary values to decimals. TQ

1 Answers   Amazon,


Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do...while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .

2 Answers  


A sample program using data structure? what is file handling?

0 Answers   TCS,


what is meant for variable not found?

3 Answers  


what is run time error?

7 Answers  


How to upgrade LOOP environment, I just mean, how can i make loop statement editable ? I just try some program using loop statement and checking it in multiple compilers. Every compiler showing different output, what's the wrong ? is it a compiler based problem, or loop based problem, tell me why ? and what will be the debugging process, for this kind of problem ?

1 Answers  


Categories