Why doesn't the code "int a = 1000, b = 1000;
long int c = a * b;" work?

Answers were Sorted based on User's Feedback



Why doesn't the code "int a = 1000, b = 1000; long int c = a * b;" work?..

Answer / larry

This won't work if int is a 16-bit size because 1000000 >
32767 (2 to the 15th - 1). It will work when int is a 32-
bit number. It will work if you cast a or b to a long.

Is This Answer Correct ?    5 Yes 0 No

Why doesn't the code "int a = 1000, b = 1000; long int c = a * b;" work?..

Answer / thirupathi reddy katkoori

Integer range exceeds if multiply both the variables the resultant value does not to store it. Due to exceeding the int range only we have to declare it as long int and the value is store in c

Is This Answer Correct ?    1 Yes 0 No

Why doesn't the code "int a = 1000, b = 1000; long int c = a * b;" work?..

Answer / guest

You must manually cast one of the operands to (long).

Is This Answer Correct ?    1 Yes 1 No

Why doesn't the code "int a = 1000, b = 1000; long int c = a * b;" work?..

Answer / vikraman85

I think mostly we should avoid assigning the variables while
declaring with the variables of another datatype..

Is This Answer Correct ?    0 Yes 1 No

Why doesn't the code "int a = 1000, b = 1000; long int c = a * b;" work?..

Answer / vignesh1988i

this will work.... correctly

Is This Answer Correct ?    0 Yes 1 No

Why doesn't the code "int a = 1000, b = 1000; long int c = a * b;" work?..

Answer / shruti

i think, the result exceeds the long int value..

the result is 10 and 6 0s..

and it exceeds the value for the long in

long int is 4 bytes..
the highest value is 65524 (m not very sure.. this could be
one of the reasons)..

Is This Answer Correct ?    0 Yes 2 No

Why doesn't the code "int a = 1000, b = 1000; long int c = a * b;" work?..

Answer / komal

it wont work as we have to declare the variable 'b'
again...we can not declare it like int a=10,b=3;
it has to b like int a=10;
int b=6;

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More C Interview Questions

What is the use of typedef in structure in c?

0 Answers  


#define f(x) main() { printf("\n%d",f(2+2)); }

5 Answers  


Explain following declaration int *P(void); and int (*p)(char *a);

3 Answers  


please send me the code for multiplying sparse matrix using c

0 Answers  


What is calloc()?

0 Answers   Adobe,






34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?

0 Answers  


how to impliment 2 or more stacks in a single dimensional array ?

1 Answers   iFlex, Microsoft,


Write a program to show the change in position of a cursor using c

0 Answers  


20. main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); } Answer:??????

2 Answers  


How can draw a box in cprogram without using graphics.h header file & using only one printf(); ?

4 Answers   NIIT,


How can I call fortran?

0 Answers  


What is auto keyword in c?

0 Answers  


Categories