C Programming - Expressions - Discussion
Discussion Forum : Expressions - Find Output of Program (Q.No. 1)
1.
What will be the output of the program?
#include<stdio.h>
int main()
{
int i=-3, j=2, k=0, m;
m = ++i && ++j && ++k;
printf("%d, %d, %d, %d\n", i, j, k, m);
return 0;
}
Answer: Option
Explanation:
Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and variable i, j, k are initialized to -3, 2, 0 respectively.
Step 2: m = ++i && ++j && ++k;
becomes m = -2 && 3 && 1;
becomes m = TRUE && TRUE; Hence this statement becomes TRUE. So it returns '1'(one). Hence m=1.
Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of i,j,k are increemented by '1'(one).
Hence the output is "-2, 3, 1, 1".
Discussion:
28 comments Page 2 of 3.
Asim vaniya said:
7 years ago
int i=-3,j=2,k=0,m;
m = ++i && ++j || ++k;
printf("\n i=%d j=%d k=%d m=%d",i,j,k,m);
What is the output of this one?
m = ++i && ++j || ++k;
printf("\n i=%d j=%d k=%d m=%d",i,j,k,m);
What is the output of this one?
Ramkumar said:
3 years ago
Hi, whether m expression will execute from left to right or right to left?
Can anyone have an idea? please describe it.
Can anyone have an idea? please describe it.
Vineela said:
1 decade ago
m=-2 && 3 && 1;
I am not getting this statement. Please explain me.
I am not getting this statement. Please explain me.
PIYUSH said:
6 years ago
How they increment the value of I, j, k by 1. Please anyone, explain it.
Don said:
9 years ago
M = -2 && 3 && 1;.
How a negative sign becomes true?
How a negative sign becomes true?
Tejanth said:
5 years ago
What would if we have post increment..i.e i++?
Please tell me.
Please tell me.
SanLakshmi said:
1 decade ago
I can't understand the AND operation.. can anyone explain it?..
Aafrin Shaqthaj said:
5 years ago
Is that the AND operator consider the negave value as True?
Murali krishna said:
1 decade ago
Can any one explain how we take binary form for -2.
Mandy said:
1 decade ago
Not able to understand that. Kindly explain again.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers