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);
}

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is else if ladder?

704


Explain is it better to bitshift a value than to multiply by 2?

820


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

742


What is bubble sort technique in c?

670


What does it mean when the linker says that _end is undefined?

748






Is struct oop?

667


What is the difference between typedef struct and struct?

715


What do you mean by a local block?

723


Write a program to print fibonacci series using recursion?

710


What is the use of header?

743


how can I convert a string to a number?

690


Why do we use stdio h and conio h?

749


Where can I get an ansi-compatible lint?

760


What are the advantages of c preprocessor?

841


If fflush wont work, what can I use to flush input?

732