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 does & mean in scanf?

595


How do you generate random numbers in C?

643


Are the variables argc and argv are local to main?

778


Explain how do you use a pointer to a function?

634


What do you mean by c what are the main characteristics of c language?

560






How many main () function we can have in a project?

602


What is a node in c?

541


which is an algorithm for sorting in a growing Lexicographic order

1387


What are the functions to open and close the file in c language?

587


What is header file definition?

561


What is the use of function in c?

702


What is s in c?

598


why use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above

646


What are the different file extensions involved when programming in C?

739


What is adt in c programming?

599