C Programming :: Increment-Decrement

Home > C Programming > Increment-Decrement > General Questions

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

1 / 45

 What will be output of the following "c" code?

#include
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

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
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

2 / 45

 What will be output of the following "c" code?

#include
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
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

3 / 45

 What will be output of the following "c" code?

#include
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
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

4 / 45

 What will be output of the following "c" code?

#include
#include
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

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
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

5 / 45

 What will be output of the following "c" code?

#include
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
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

6 / 45

 What will be output of the following "c" code?

#include
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
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

7 / 45

 What will be output of the following "c" code?

#include
#define plus +
#define minus +plus
int main(){
long x,i=3;
x=++i;
printf("%ld",x);
return 0;
}

A4

B3

C0

D6

ECompilation error

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

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

8 / 45

 What will be output of the following "c" code?

#include
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
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

9 / 45

 What will be output of the following "c" code?

#include
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

Answer: Option E

Explanation:

error: invalid lvalue in decrement

Workspace

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

10 / 45

 What will be output of the following "c" code?

#include
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