1,487 views
1 1 vote
#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 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
Position:
Show:

Related questions

0 0 votes
1 1 answer
462
462 views
Rajib Datta Roy asked Dec 26, 2023
462 views
#include <iostream>using namespace std;int main(){ float a,b,c; cout<<"Enter a="; cin>>a; b=a + (1-1); cout<<"a + (1-1)="<<b<<endl; c=(a+1)-1; cout<...
1 1 vote
3 3 answers
1.0k
1.0k views
shiva0 asked Apr 3, 2019
1,035 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 3 votes
2 answers 2 answers
2.6k
2.6k views
sid1221 asked Jul 25, 2017
2,630 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 0 votes
1 1 answer
720
720 views
radha gogia asked Aug 10, 2015
720 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...