583 views
1 votes
1 votes
#include <stdio.h>
 
int main()
{
   long int a = 0x7fffffff * 0x7fffffff;
   long int b = 0x7fffffff * 0x7fffffffl;
   printf("a = %ld, b = %ld\n", a, b);
   return 0;
}

What will be output if sizeof(int) is 4 and sizeof(long int) is 8.

1 Answer

Best answer
2 votes
2 votes

Basic Point :- 

let take b=5,c=2

float a = b/c ====> a=2.0 why?

because by precedence and associativity, (float a) = (b/c) ===> equal operator is right associative, therefore (b/c) evaluates first

b and c are integers ===> after evaluating b/c, it will convert to int and returns 2

if atleast either one of the b and c are float ===> after evaluating b/c, it will convert to float and returns 2.5

 

long int a = 0x7fffffff * 0x7fffffff;

0x7fffffff * 0x7fffffff ==> ( 3FFFFFFF00000001 )H it is long int but our operands are int, therefore convert into int ===> ( 00000001 )H . ===> long int a = ( 00000001 )H  = ( 1 )10

 

long int b = 0x7fffffff * 0x7fffffffl;

0x7fffffff * 0x7fffffff ==> ( 3FFFFFFF00000001 )H it is long int but one of our operands is long int, therefore convert into long int ===> ( 3FFFFFFF00000001 )H . ===> long int b = ( 3FFFFFFF00000001 )H = ( 4611686014132420609 )10

selected by

Related questions

1 votes
1 votes
3 answers
2
shiva0 asked Apr 3, 2019
472 views
What is the output of the program? int main() { union a { int i; char ch ; }; union a u; u.ch[0] = 3; u.ch = 2; printf("%d, %d, %d", u.ch[0], u.ch , u.i); return 0; }
3 votes
3 votes
2 answers
3
sid1221 asked Jul 25, 2017
1,365 views
#include<stdio.h int main() { char c = 125; c = c+10; printf("%d", c); return 0; }what will be the output , explain with logic(size of char 1 byte)
0 votes
0 votes
1 answer
4
radha gogia asked Aug 10, 2015
403 views
CASE A: CASE A: &#8234;#&lrm;include&#8236;<stdio.h int divide( int a, b) { return 7; } int main() { int a=divide(8,3); printf("%d",a); return 0; }CASE B :CASE B : #inclu...