retagged by
353 views
2 2 votes

Size of $\verb|int|$ is $\mathrm{2~B}$ and size of $\verb|float|$ is $\mathrm{4~B}$

Consider the following C++ program:

#include<iostream>

using namespace std;

int main()
{
    int a = 4;
    float b = 3;
    
    cout << sizeof(++a + b) << " ";
    cout << a;
    
    return 0;
}

What will be the output produced by the above program?

  1. $4~5$
     
  2. $4~4$
     
  3. $6~5$
     
  4. $4~6$

1 Answer

0 0 votes

Key concept : 

1. sizeof does not evaluate  the expression  inside it .

2. It only check  the type of expression  at comile time.

3. so ++a  is not executed 

step 1  ++a  + b  

a = int 

b  = float 

int + float = float ;

sizeof(float) = 4 

++a. is not executed so value of a remain same . 

so final ouptuput =  4 4 

so option B is correct. 

 

Answer:
Position:
Show:

Related questions

1 1 vote
1 1 answer
231
231 views
GO Classes asked Mar 17
231 views
Consider the following C++ program:#include using namespace std; template void func(T x) { static int count = 0; cout << x << " " << ++count << endl; } int main()...
1 1 vote
1 1 answer
233
233 views
GO Classes asked Mar 17
233 views
Consider the following C++ program:#include using namespace std; void modify(int &a, int &b, int &c) { a = 2; b = 6; c = 14; } int main() { int x = 1, y =...
0 0 votes
0 0 answers
196
196 views
GO Classes asked Mar 17
196 views
Which of the following is false about Operator Overloading in C++$\texttt{::}$ operator cannot be overloaded A unary operator can be overloaded to act as a binary operat...
1 1 vote
0 0 answers
392
392 views
GO Classes asked Mar 17
392 views
Consider the following C program:#include <stdio.h void func(int *a, int *b) { int i = (*a) * (*b); int *j = b; for (;;) { if (i 20) ...