Question
#include using namespace s t d ; main ( ) { struct f o o t { int x [ 1 0 0 ] ;
#include using namespace s t d ;
main ( ) {
struct f o o t { int x [ 1 0 0 ] ; int va r 1 ; int y [ 1 0 ] ; } f o o ; int va r 2 ; long i ; int p , q ; short int s ; long int l ; struct f o o t bar [ 5 0 ] ;
for ( i =0; i <100; i++) f o o . x [ i ]=100+ i ;
for ( i =0; i <10; i++) f o o . y [ i ]=200+ i ;
f o o . va r 1 = 2 5 0; cout << s i z e o f ( s ) << ;
cout << s i z e o f (p ) << ;
cout << s i z e o f ( l ) << ; q = ( int ) &f o o ;
cout << q << ; p=&( f o o . x [ 5 ] ) ;
cout << p << ; // POINT 1 q = ( int ) &va r 2 ;
cout << q << ; q = p+16;
cout << q << ;
i = ( (long ) p ) + 1 6; q = ( int ) i ; cout << q << ;
s = ( short ) i ; cout << s << ;
l = (long ) i ;
cout << l << ; q = p+95;
cout << q << ; q = p+98;
cout << q << ;
i = ( (long ) p ) + 1 7; q = ( int ) i ;
cout << q << ; q = p + ;
cout << q << ; q = ( int ) ( ( ( long ) p ) + ) ;
cout << q << ; p = ( int ) bar ; ( p + ) = 5 0 0;
cout << bar [ 8 ] . va r 1 << ; }
After understanding the program, can you make any conclusions about how C/C++ interpret addition on integers and pointers? Are they the same? Explain.
7. The program contains three blanks. Fill the first two with appropriate integer constants to print 205 for both new outputs. Depending on your platform, it is possible (though unlikely) that your original program will have given a strange error message (e.g., bus error, segmentation error) before you get to this point. If so, you may get rid of the lines causing this error first.
8. Fill in the third blank in the program to print 500.
9. Does your compiler allocate local scalar variables growing up or down in memory? Explain how you know this from your program output.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started