What is the output of the following program:

Code
  1. int main()

  2. {

  3. char a = 120, b = 140;

  4. int i;

  5. i = a + b;

  6. printf("%d", i);

  7. return 0;

  8. }
Copyright GeekInterview.com

a) 260
b) 0
c) -1
d) 1

Questions by lalithakasiraj

Showing Answers 1 - 39 of 39 Answers

deepti mahajan

  • Jan 24th, 2013
 

a) 260

  Was this answer useful?  Yes

lakhpat

  • Mar 3rd, 2013
 

A=120
b=-116...(signed char range ie 127 to -128...... so 140 convert into -116).
c=a+b(120+(-116));
c=4;

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. void main()

  4. {   clrscr();

  5.     char a=120,b=140;

  6.     int c;

  7.     c=a+b;

  8.     printf("%d%d%d",a,b,c);

  9.     getch();

  10. }

it will be 4;
der is no any option unfortunately;
bcoz a=120 and b=140 but b can,t exceed 127. after 127 it will be -128,-127,-126.......up to -116;
so updated a and b will be 120, -116 respectively;
so final value will be 4:

  Was this answer useful?  Yes

gjkb

  • Nov 12th, 2013
 

260

  Was this answer useful?  Yes

kadukuntla rambabu

  • Nov 21st, 2013
 

options are wrong ,correct answer is 4.

  Was this answer useful?  Yes

nani

  • Nov 22nd, 2013
 

option (1).260....

  Was this answer useful?  Yes

ANBARASAN R

  • Nov 25th, 2013
 

4

  Was this answer useful?  Yes

nanirajesh gullapalli

  • Jan 6th, 2014
 

260

  Was this answer useful?  Yes

ish mahajan

  • Jan 16th, 2014
 

260

  Was this answer useful?  Yes

Surajsingh Rajput

  • Feb 12th, 2014
 

the answer is 4. because range of char is -128 to 127 so at 140 it get considered as 127,-128,-127,-126,....,-116.
so 120+(-116)=4

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions