what will be the output of this program?
void main()
{
int a[]={5,10,15};
int i=0,num;
num=a[++i] + ++i +(++i);
printf("%d",num);
}
Answers were Sorted based on User's Feedback
Answer / apekshit jotwani
Answer will be 15.
Consider a[++i]=x
++i=y
++i=z
so v have to evaluate x+y+z
Compiler converts this to postfix as "xy+z+"
so x is put in the stack 1st i=1,x=a[1]=10
Then i=2, 2 is put in the stack
Then x+y is operated = 12
12 is put in the stack.
Then i=3, 3 is put in the stack.
Then 12+3=15,
only 15 is put in the stack. That is the final answer
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / ricky
Garbage Value
num=a[++i] + ++i +(++i);
in this line the last i will be incremented first
so the last ++i will return 1 after that the middle ++i will return 2 now the value of i will change every where in the program now the first ++i will return 3 since the array starts with a[0] and ends at a[2] there is no a[3] and hence it will print garbage value
| Is This Answer Correct ? | 5 Yes | 3 No |
Answer / abc
initially i=0;
num=a[++i]+ ++i + ++i;
num=a[1]+2+3
num=10+2+3=15
| Is This Answer Correct ? | 1 Yes | 0 No |
How can you convert integers to binary or hexadecimal?
What is the difference b/w Structure & Union?
Find the O/p of the following struct node { char *name; int num; }; int main() { struct node s1={"Harry",1331}; struct node s2=s1; if(s1==s2) printf("Same"); else printf("Diff"); }
write a program to print data of 5 five students with structures?
What is an example of structure?
what is the return value (status code) of exit() function.... what the arguments(integer value) passed to it means....
Can include files be nested?
can a union be self-referenced?
when user give a number it multiply with 9 without useing '+' and '*' oprator
the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b
find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2
what is the diff between the printf and sprintf functions?? and what is the syntax for this two functions ??