C Programming :: Increment-Decrement

NA
SHSTTON
39
Solv. Corr.
27
Solv. In. Corr.
66
Attempted
0 M:15 S
Avg. Time

1 / 45

What will be output of the following "c" code?
#include<stdio.h>
void main() { 
int i=-1,j=-1,k=0,l=2,m;  
m = i++ && j++ && k++ || l++;  
printf("%d %d %d %d %d",i,j,k,l,m); 
}

A0 0 1 3 1

B1 1 0 2 0

C2 2 1 3 1

DNone of these

E-1 -1 0 2 1

 View Answer |  Discuss in Forum |  Workspace | Asked In Societe Generale |

Answer: Option A

Explanation:

=>Logical operations always give a result of 1 or 0 .
=> Logical AND (&&) operator has higher priority over the logical OR (||) operator.

So the expression i++ && j++ && k++ is executed first. The result of this expression is 0 (-1 && -1 && 0 = 0)

Workspace

NA
SHSTTON
79
Solv. Corr.
41
Solv. In. Corr.
120
Attempted
1 M:4 S
Avg. Time

2 / 45

What will be output of the following "c" code?
#include<stdio.h>
void main(){
    int i=5,j=10,num;
    num=(++i,++j,i+j);
    printf("%d  %d  %d",num,i,j); 
}

A17 6 11

B6 6 11

C15 6 11

D15 5 10

ECompilation error

Answer: Option A

Explanation:

Int =5 is replace with 6, j=10 replace with 11,num;   

 Seen  below how it will 

Num=(++I=1+5=6,++j=1+10=11,I+j=6+11=17);

Workspace

NA
SHSTTON
117
Solv. Corr.
54
Solv. In. Corr.
171
Attempted
0 M:10 S
Avg. Time

3 / 45

What will be output of the following "c" code?
#include<stdio.h>
void main()
{
int i=5;
printf("%d",i+++++i);
}

A5

B6

CCompiler Error

D7

Answer: Option C

Explanation:

The expression i+++++i is parsed as i ++ ++ + i which is an illegal combination of operators.

Workspace

NA
SHSTTON
12
Solv. Corr.
86
Solv. In. Corr.
98
Attempted
2 M:46 S
Avg. Time

4 / 45

What will be output of the following "c" code?
#include<stdio.h>
#include<conio.h>
void main(){
    int a,i=4;
    a=- -i+- -i+- -5;
    printf("%d %d",a,i);
}

A13 4

B-3 2

C7 2

D-13 4

ECompilation error

 View Answer |  Discuss in Forum |  Workspace | Asked In Societe Generale |

Answer: Option A

Explanation:

void main()

{

int a,i=4;

int z=5;

\\*a=--i+--i+--5;*// error

a=--i+--i+--z;

printf("%d %d",a,i);}

answer 

 output  ia=8 i=2


Workspace

NA
SHSTTON
27
Solv. Corr.
66
Solv. In. Corr.
93
Attempted
2 M:8 S
Avg. Time

5 / 45

What will be output of the following "c" code?
#include<stdio.h>
int main()
{
int i=5,j=6,z;
printf("%d",i+++j); 
return 0;
}

A12

B11

C13

DCompilation Error

ENone of these

Answer: Option B

Explanation:

the expression i+++j is treated as (i++ + j)

Workspace

NA
SHSTTON
14
Solv. Corr.
75
Solv. In. Corr.
89
Attempted
0 M:46 S
Avg. Time

6 / 45

What will be output of the following "c" code?
#include<stdio.h>
void main(){
    int num,a=10;
    num=a--- -a--;
    printf("%d  %d",num,a);
}

A0 8

B0 10

C20 8

D-1 10

ECompilation error

Answer: Option C

Explanation:

int num,a=10;
num=a-- - -a--;  //  (10 - -9) =19   last a-- = 8 so final answer will be 19, 8
printf("%d %d",num,a);

Workspace

NA
SHSTTON
60
Solv. Corr.
5
Solv. In. Corr.
65
Attempted
0 M:0 S
Avg. Time

7 / 45

What will be output of the following "c" code?
#include<stdio.h>
#define plus +
#define minus +plus
int main(){
    long x,i=3;
    x=++i;
    printf("%ld",x);
    return 0;
}

A4

B3

C0

D6

ECompilation error

 View Answer |  Discuss in Forum |  Workspace | Asked In Societe Generale |

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
5
Solv. Corr.
59
Solv. In. Corr.
64
Attempted
0 M:0 S
Avg. Time

8 / 45

What will be output of the following "c" code?
#include<stdio.h>
void main(){
    int a[]={5,10,15};
    int i=0,num;
    num=a[++i]+ ++i+(++i);
    printf("%d",num);
}

A6

B17

C16

D12

ECompilation error

Answer: Option A

Explanation:

its answers is 15. here num=a[1]+2+3;

where a[1]=10

so answer will be

a=10+2+3

a=15;

Workspace

NA
SHSTTON
8
Solv. Corr.
56
Solv. In. Corr.
64
Attempted
0 M:19 S
Avg. Time

9 / 45

What will be output of the following "c" code?
#include<stdio.h>
void main(){
    int num,a=5;
    num=---a;
    printf("%d  %d",num,a);
}

A-4 4

B3 3

C-4 5

D-10

ECompilation error

 View Answer |  Discuss in Forum |  Workspace | Asked In Societe Generale |

Answer: Option E

Explanation:

error: invalid lvalue in decrement

Workspace

NA
SHSTTON
11
Solv. Corr.
52
Solv. In. Corr.
63
Attempted
0 M:0 S
Avg. Time

10 / 45

What will be output of the following "c" code?
#include<stdio.h>
int main()
{
int i=5;
printf("%d %d %d %d %d %d",i++,i--,++i,--i,i);
return 0;
}

A5 4 4 5 4

B4 5 5 4 5

C4 5 5 5 5

DCompilation error

Answer: Option C

Explanation:

The arguments in a function call are pushed into the stack from left to right.
The evaluation is by popping out from the stack. and the evaluation is from right to left, hence the result.

Workspace